0

I have the following simple form:

<form>
    <input name="default" type="date" required="required" /><br />
    <input name="maxDate" type="date" required="required" />
</form>

If I init the jQuery UI Datepicker plugin like this:

$('input[type=date]').datepicker({
    dateFormat: "yy-mm-dd"
});
$('input[name="maxDate"]').datepicker('option', {
    maxDate: 0
});

The second input with the extended options will be invalid on page load (see the attached JSfiddle), until I open the datepicker in it and set some values.

I checked the Datepicker Widget API, but it looks to be the valid way to give extra option to the selected datepicker instance. Am I doing something wrong?

Thank you in advance :)


EDIT: Screenshot attached (FF 41)

enter image description here

16
  • what is the problem with jsfiddle, seems it's working fine? Commented Nov 5, 2015 at 13:03
  • maxDate: 0 also working fine on second field. Commented Nov 5, 2015 at 13:04
  • You should change input type from date to text or use Modernizr or similar library to feature detect if the browser supports the input type=date, and then load the jQuery UI datepicker if if does not. Maybe you get confused that in some browsers html5 datepicker is upon the other one and you can't see it. Commented Nov 5, 2015 at 13:10
  • @DeepakBiswal Check it in Firefox; isn't the second input red at your browser? (See screenshot) Commented Nov 5, 2015 at 13:17
  • @calinaadi: Yes, it's the same also with input type=text. Commented Nov 5, 2015 at 13:19

1 Answer 1

0

You can call destroy and then reinitialize desired datepicker:

$('input[name="maxDate"]').datepicker("destroy"); $('input[name="maxDate"]').datepicker({maxDate: 0,dateFormat: "yy-mm-dd"});

like here: Change option dynamically in JQuery UI DatePicker fails

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Finally, i wrote the following function, based on your answer: $.fn.customizeDatepicker = function(newOptions) { var globalOptions = $(this).datepicker('option', 'all'); $(this).datepicker('destroy').datepicker($.extend(globalOptions, newOptions)); return this; };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.