Reputation: 1942
I have a table of Rangepicker of the date and the time, this table is dynamically which I can add and remove these range picker as you look at the picture below :
I want to store these values on another table to send it to the backend and when I have value on the Rangepicker, I get an error.
My code is :
import { DatePicker } from 'antd';
import moment from 'moment-timezone';
import fr_FR from 'antd/lib/locale-provider/fr_FR';
import "moment/locale/fr";
const { RangePicker } = DatePicker;
export default class App extends Component {
constructor(props) {
super(props);
this.state= {
tranches :[{date:null}]
}
onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString)
}
onOk(value) {
console.log('onOk: ', value);
}
render() {
return (
<div>
{
this.state.tranches.map((el, i) =>
<Row key={i}>
<Col span={12}>
<label className="pt-label .modifier"><strong>Période</strong></label>
<LocaleProvider locale={fr_FR}>
<RangePicker
allowClear={false}
id="date" name= "date"
style={{ width: '547px', marginLeft:'20px'}}
locale="fr"
//placeholder={["Date de début","Date de fin"]}
separator="-"
onChange={this.onChange}
showTime={{ format: 'HH:mm' }}
format="DD/MM/YYYY HH:mm"
placeholder={['Date et heure de début', 'Date et heure de fin']}
onOk={this.onOk}
/>
</LocaleProvider>
</Col>
<Col span={12}>
{i === 0 ?
<>
<Icon type="plus-circle" theme="twoTone" twoToneColor="#52c41a" onClick={this.ajouterTranche}/>
<br/>
</>
:
<>
<Icon type="close-circle" theme="twoTone" twoToneColor="red" onClick={this.supprimerTranche(i)}/>
<Icon type="plus-circle" theme="twoTone" twoToneColor="#52c41a" onClick={this.ajouterTranche}/>
<br/>
</>
}
</Col>
</Row>
)}
}
How can I fix it ?
Upvotes: 0
Views: 22581
Reputation: 87
onChangeDate(value) {
this.setState({date: value});
};
onChange{this.onChangeDate.bind(this)}
Upvotes: 0
Reputation: 1238
Change
onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString)
}
to
onChange = (value, dateString) => {
let date = this.state.date
date.push(value)
this.setState({date: date})
}
Link here The x icon is not functional in the above link
Upvotes: 4