Topic: DatePicker reactJs

belsem free asked 5 years ago


I have read the documentation for date picker, but I do not see how to get the date selected, can anyone help me. Thank you

Jakub Strebeyko staff answered 5 years ago


Hi there belsem,

I personally suggest taking these three simple steps:
1. creating a constructor function where the parent component's state would be defined (say, "appointment"), initially pointing at null;
2. there is a handler for an onChange event on the DatePicker, so have it trigger a custom function as a callback (say, onChange={this.handleDateChange});
3. define your handleDateChange callback, say

onChange = (e, date) =>{
    console.log(e);
    console.log(date);
    this.setState({
      appointment: date
    });
}

This would also be where you'd convert the date format as needed, using f.e. moment API (moment(date).format('DD-MM-YYYY')).

Hope it helps.

With Best Regards,
Kuba



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags