DateTime Standalone - how to update minDate
DateTime Standalone - how to update minDate
Hi,
I want to update the minDate for a second DateTime field based on the selected date of a first DateTime field.
I can update the value of the second field using this:
var dd1 = new DateTime(document.getElementById('departure_date_1'), {
format: 'DD/MM/YYYY HH:mm',
onChange: function (value, date, input) {
ad1.val(date);
}
});
var ad1 = new DateTime(document.getElementById('arrival_date_1'), {
format: 'DD/MM/YYYY HH:mm',
});
But I can't figure out how to update the minDate, this does not work:
var dd1 = new DateTime(document.getElementById('departure_date_1'), {
format: 'DD/MM/YYYY HH:mm',
onChange: function (value, date, input) {
ad1.val(date);
}
});
var ad1 = new DateTime(document.getElementById('arrival_date_1'), {
format: 'DD/MM/YYYY HH:mm',
});
Any ideas?
Thanks
- Tom
This question has an accepted answers - jump to answer
Answers
Sorry, I meant this does not work:
I'm not sure why the DateTime API docs don't seem to be available. @allan will need to look at this.
I opened this basic example and checked the API:
It looks like the API is
min()
notminDate()
. Try usingad1.min(date);
and let us know the results.Kevin
Looks like I've messed up my nginx config for that path - sorry. I'll look into that. In the meantime, if you go directly to https://datatables.net/extensions/datetime/api/ it will load the API methods, which as Kevin notes, will be
min()
in this case.Allan
Hi,
That's working now thanks when using min()
A follow on question, can I get the second 'arrival_date_1' field to now display the minDate when opened rather than today? I was hoping this might work:
But it is throwing an error.
Thanks
- Tom
What error are you getting?
Where are you using
ad1.display( date.getFullYear(), date.getMonth() );
?I copied your code into this test case and tried using the
display()
API in theonChange
event and got this error:I bit of debugging and it looks like the Datetime input for
arrival_date_1
has not fully initialized:I removed the
onChange
event and created thisclick
event:Here is the test case:
https://live.datatables.net/vicomohe/1/edit
I think it does what you are looking for. If not please update the test case to show the issue you are having.
Kevin
Kevin,
Hi - yes I was getting that same error:
Your solution is great and gives me exactly what I was looking for.
Thanks
- Tom
Just to follow up - the link for the API docs for DateTime is working now.
Allan