pickadate.js
pickadate.js copied to clipboard
Automatically initialize based on the value of the bound input
If I render an input from my server with an ISO8601 date and I call .pickadate
on that input, pickadate doesn't re-render the contents of that input based on whatever format it was configured with.
What is the correct approach to tell pickadate to read value
on my input, parse it and reformat upon initialization?
Same issue here.
+1 for this -- The date shows as '24 November 2016' when you select it using the picker, but when you initialise the underlying field with a date (e.g. 2016-10-24), it simply appears with the same, unformatted value '2016-10-24'.
I managed to fix it for default values with the following:
$( 'input[type="date"]' ).pickadate(
{
onStart:function(){
this.set( 'select', Date.parse( $( this.$node ).val() ) );
}
}
);
...which is fine if the value is set when the field is initialised. However, if you set the value later (via JavaScript), it doesn't help. I tried using this:
$( 'input[type="date"]' ).change(
function(){
$( this ).pickadate( 'picker' ).set( 'select', Date.parse( $( this ).val() ), {muted:true} );
}
);
...but I get a 'too much recursion' error, so obviously pickadate is updating the input field itself internally, even when 'muted' is set to true.
I suppose I could address pickadate directly to set the date, but I'd rather not tie my other code to pickadate -- the field might be updated by anything, so I don't want to have to have all my code be aware of pickadate.
Not sure how to solve this one, I might have to look for an alternative date picker.
$('.datepicker').on('change', function() { let date = new Date($(this).val()); let nextDay = new Date(date); nextDay.setDate(date.getDate() + 1); endDatepicker.pickadate('picker').clear().set('min', nextDay); });