1
Hello, I am trying to "popular" a textarea with a value, but when I try to edit the field and it does not allow. I tried using the property "defaultValue" but the field is empty. It follows parts of the code:
class TaskForm extends React.Component {
constructor(props) {
super(props);
this.apis = new APIs();
this.state = {
taskEdit: [],
title: '',
description: '',
project: '',
service: '',
date: moment(),
};
}
componentDidMount() {
this.setState({ isLoading: true });
this.apis.editTask(this.props.location.state.id)//usar isso aqui
.then(taskEdit => {
return this.setState({
taskEdit: taskEdit ? taskEdit : {},
isLoading: false
});
});
}
handleChange(event) {
this.setState({[event.target.name]: event.target.value});
}
render() {
const { taskEdit } = this.state;
const { history } = this.props;
return (
<Layout history={history} styleName='container'>
<aside>
{taskEdit.title}
{taskEdit.description}
</aside>
<main>
<h1>{this.state.id}</h1>
<form onSubmit={this.handleSubmit}>
<h2>Edit Task</h2>
<br/>
<span>
Title:
<input defaultValue={taskEdit.title} type="text" size="100" className='title' name='title' onChange={this.handleChange}/>
</span>
<br/>
<br/>
<span>
Description:
<textarea value={taskEdit.description} type="text" className='description' name='description' onChange={this.handleChange}/>
</span>
<br/>
<br/>
</form>
</main>
<aside>
</aside>
</Layout>
);
}
}
export default TaskForm;
I don’t know if it has anything to do with it....
<textarea>
does not support value attribute.– hugocsl