I am developing start date and end date field screen using React JS and Bootstrap now I need add validation for end date field. For example : start date 01/01/2021 end date should allow to select from 01/01/2021(start date) up to 3 years(01/01/2023).
if I use datepicker I can use the min and max attributes but am using bootstrap date <Form.Control type="date" name="endDate" placeholder="endDate" onChange={this.endDatemyChangeHandler}/>
do not have these attributes.
a) how can I achieve min and max attribute?.
b) I am using the placeholder="endDate"
but in UI still showing the dd/mm/yyyy instead of endDate
c) Is it possible to enable the date field to enter dates from keyboard?
below is my complete code
import React from 'react'
import { Form } from 'react-bootstrap';
import './download.css';
import "./App.css";
class BootstrapDate extends React.Component{
constructor(props) {
super(props);
this.state = { startDate: '' };
}
myChangeHandler = (event) => {
this.setState({startDate: event.target.value});
}
endDatemyChangeHandler = (event) => {
this.setState({endDate: event.target.value});
}
mySubmitHandler = (event) => {
event.preventDefault();
alert("You are submitting "+"startDate==" + this.state.startDate +"endDate=="+ this.state.endDate);
}
render(){
return(
<div id="container">
<link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"></link>
<img src="\is.jpg" id="ui-image"></img>
<div className="row">
<div className="col-md-4">
<Form.Group controlId="startDate">
<Form.Control type="date" name="startDate" placeholder="startDate" onChange={this.myChangeHandler}/>
</Form.Group>
</div>
<div className="col-md-4">
<Form.Group controlId="endDate">
<Form.Control type="date" name="endDate" placeholder="endDate" onChange={this.endDatemyChangeHandler}/>
</Form.Group>
</div>
</div>
<p id="note_bootstrap">Note: Only up to 3 years worth of Data can be downloaded</p>
<div>
{ this.state.startDate && this.state.endDate &&
<button id="button_bootsrap" onClick={this.mySubmitHandler} variant="primary" className="fa fa-download" >Download</button>
}
</div>
</div>
)
}
}
export default BootstrapDate;