Datepicker Validation Not Working

I am using datepicker in custom script. It is working fine and I want to put a validation on startdate and end date as:

→ startdate shouldn’t be greater than enddate

→ enddate should be after of start date

This is my code:

 $('#start_date').datepicker({
  format: "yyyy/mm/dd",
  autoClose: true,
  autoOpen: false,
  language: 'en-US',
 onSelect: function(selected) {
alert(selected)
$('#end_date').datepicker("option", "minDate", selected);
        }
 });	
 $('#end_date').datepicker({
  format: "yyyy/mm/dd",
  autoClose: true,
  autoOpen: false,
language: 'en-US',
onSelect: function(selected) {
alert(selected)
$("#start_date").datepicker("option","maxDate",selected);
        }
 }); 

The alert I used is displaying the value ie date but validation isn’t working. Can anyone help me what I am doing wrong ??

Let us know if this helps https://erpnext.org/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/date-validation

I am using html for making that field. So can you help me with this

well ok I am on thin ice - for me to help you would need to teach me what you know :wink:

It could be a great standard data type : Date Range
One field typed “date range” with option min and another field typed “date range” with option max

Currently using ajax data-table for showing data as frappe data-table is having pagination issue right now. For that i simply created a table in html on form page and within that html code, i used a field for setting field. Now I am trying to put validations between those fields (described above). The websites to which I landed via Google, searching for this query, about every site told me the same but that didn’t worked.
I am using ERPNext v11 and it is currently using ES6 java-script standard so this might be the issue that some syntax or way of doing it might have changed (just a blind guess).

Thanks for sharing, to explain your context engages others to follow you and learn

A reference implementation say for eg here may give you clues
https://datatables.net/examples/api/form.html

If a search of discuss.erpnext does not give you ideas to your question, a search on ‘datepicker’ ‘validation’ might land you some code to point the way Recent Discussions — DataTables forums

Maybe share your datatable or any validation code for more context?

Syntax errors should show up in web console or server logs, depending on the case.

There is an existing datatype in Frappe called “DateRange” that takes a 2-member list of the start and end dates, and automatically validates them. It’s already being used in a couple of reports.

Not sure about the best way to solve your problem, but you may have fewer headaches with this datatype.

Just my 2 cents.

2 Likes

Thank you

Used parse method of js to convert both dates and then comparison worked as it was supposed to be.

Thanks BTW :slight_smile: