Options on DateTime
Options on DateTime
I am trying to link two datetime fields together so that the Start Date can not be more than the End Date and vice versa.
I can't seem to find the list of options available for the DateTime field built into Editor.
My other option is to use Bootstrap DateTimePicker (2): I have added the JS and CSS but Editor does not seem to want to use this version.
Perhaps I am confused how both work as I am fairly new to Editor.
Any help would be appreciated.
This question has accepted answers - jump to:
Answers
I think this is usually done at the back end using validators. Here is the link for PHP:
https://editor.datatables.net/manual/php/validation
For example I use my own validator here:
The methods for the
datetime
field are in its documentation (anchor link). In this case you would want to useeditor.field(...).minDate(...)
.You should use
field().input()
to get theinput
element so you can assign achange
event listener to the state date field.Allan
Thank you for pointing me in the right direction Allan. This is working in the Editor. I will also be using back end validation as well thanks to rf1234's suggestion.
I am also trying to use the datetime outside the Editor. I create a new instance of the DateTime:
However when I try to use an on change with the input, it never fires.
How do I access the DateTime outside of the dataTable in order to fire the on change event?
Thanks for your time.
That's not something that is currently documented or indeed directly supported. It was / is my intention to make that available in future, but at the moment it might be hit and miss as it isn't something I have tested.
You should be able to just use
$('#myInput').on('change', ... );
like you would with any other input element.Allan
Hey Allan,
I am using the
$('#myInput').on('change', ... );
but this is what is not firing.The only time that it fires is when I manually change the box, not on selection of a date.
I need to be able to check the on change events in order to establish start and end dates that supplement each other (min and max dates) as well as tell the DataTable that I am passing in new filter requirements for those start and end dates (server side processing).
Thank you.
Ah! I've just looked at the Editor source and this is what it does for the field type:
So you need to use the
onChange
callback. It doesn't triggerchange
automatically (I remember now) to be like howinput
elements work.Allan
Thank you Allan,
That worked perfectly.