admin管理员组文章数量:1293916
I have a Signup form that takes a date as input.
The code of my date input is:
birthDate: new Date(),
this.handleSubmit = this.handleSubmit.bind(this);
this.handledChange = this.handledChange.bind(this);
handledChange(date) {
this.setState({
birthDate: date
});
}
<ControlLabel>Date de naissance</ControlLabel>
<FormGroup controlId="birthDate" bsSize="large">
<FormControl
autoFocus
type="date"
value={this.state.birthDate}
onChange={this.handledChange}
/>
</FormGroup>
When I submit it, the input date is undefined
on the console.
I want it in the format : YYYY-MM-DD
How can I fix that please?
I have a Signup form that takes a date as input.
The code of my date input is:
birthDate: new Date(),
this.handleSubmit = this.handleSubmit.bind(this);
this.handledChange = this.handledChange.bind(this);
handledChange(date) {
this.setState({
birthDate: date
});
}
<ControlLabel>Date de naissance</ControlLabel>
<FormGroup controlId="birthDate" bsSize="large">
<FormControl
autoFocus
type="date"
value={this.state.birthDate}
onChange={this.handledChange}
/>
</FormGroup>
When I submit it, the input date is undefined
on the console.
I want it in the format : YYYY-MM-DD
How can I fix that please?
Share edited Jan 18, 2019 at 22:40 user933941 asked Jan 18, 2019 at 21:31 Ichrak MansourIchrak Mansour 1,94212 gold badges37 silver badges64 bronze badges3 Answers
Reset to default 4You won't get selected date directly it should be through event target
Change
handledChange(date) {
this.setState({
birthDate: date
});
}
To
handledChange(event) {
this.setState({
birthDate: event.target.value
});
}
You can also extract the input value of your form using its Id, after submission.
You can try using like this in your submit method:
let selectedDate = document.getElementById('birthDate')
BirthDate here refers to controlId of FormGroup
This works like a gem. please try it out if you are still facing the issue
<input
type="date"
name="expiration date"
value={this.state.expiration_date}
onChange={event => this.setState({expiration_date: event.target.value})}
/>
onChange = (key, value) => {
this.setState({
[key]: value
})
}
本文标签: javascriptHow to get the value of the date input in ReactJSStack Overflow
版权声明:本文标题:javascript - How to get the value of the date input in ReactJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741591261a2387141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论