only submit server side request when date in date range is in valid format

39 Views Asked by At

I am using YADCF with date range filter. I am using the jQuery-ui datepicker type. Data is returned to the datatable from AJAX requests (serverSide is set in the datatables config).

This works fine as long as the user selects a valid date from the UI box. However, the user can also enter free text into the box (e.g '20') and when this happens the server side raises an exception and returns error 400. This is ok but the ideal solution would be for the date format to be validated client-side, and the AJAX request is only sent when there is a valid date in the range box.

Is it possible to configure yadcf / datatables to only submit AJAX requests when there is a valid date?

yadcf.init(table, [
  {
    column_number: 0,
    filter_type: 'range_date',
    datepicker_type: 'jquery-ui',
    date_format: 'yyyy-mm-dd',
    filter_delay: 500,
    filter_container_id: 'timestamp_range_picker'
  }
]

enter image description here

1

There are 1 best solutions below

0
Tyler P On

You should probably fix this issue at the source, which is your input box. Set it as a date type and then there will be no chance of incorrect entry.

<input type="date" />