After selecting a date from the dropdown calendar and setting the time the value is automatically submitted. However, I want use the submit button to submit the value. From research I thought, 'event.preventDefault();', statement was suppose to prevent such a thing. Also, is the value stored in inputValue? If it is, how do I access that value from outside the calendar class?
So, again to be clear, I want to submit the value using the submit button.
class Calendar extends React.Component {
constructor(props) {
super(props);
this.state = {
inputValue: '',
}
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.state.inputValue = event.target.valueAsNumber;
console.log('Form value: ' + this.state.inputValue);
event.preventDefault();
}
handleSubmit(event) {
this.state.inputValue = event.target.valueAsNumber;
console.log('Form value: ' + this.state.inputValue);
event.preventDefault();
}
render() {
return (
<div className="Calendar">
<form onSubmit="return handleSubmit();">
<label>Date/Time</label>
<input type="datetime-local" value={this.state.inputValue} onChange={this.handleChange()} />
<input type="submit" value="Submit" />
</form>
</div>
//{this.render(){return (<UserList />)};
);
}
};
export default Calendar;