I am trying to override my datepicker plugin and implement my own custom datepicker. I'm putting my code in a global js file in order to override as soon as the page loads.
(function($) {
var originalVal = $.fn.datepicker;
$.fn.datepicker = function(val1, val2, val3) {
console.log(val1); // option
console.log(val2); // maxDate
console.log(val3); // 09/06/2017
// var dp = originalVal.clone();
// console.log(dp);
var _options = {
changeYear: true,
changeMonth: true
}
if (val1 == "option") {
_options[val2] = val3
console.log(_options[val2]);
}
else {
_options = $.extend(_options, val1)
}
console.log(_options); //Object { changeYear: true, changeMonth: true, maxDate: Date 2017-09-06T06:52:32.449Z }
return originalVal.call(this, _options);
};
})(jQuery);
This works perfectly as the page loads and changeYear and changeMonth is available along with restriction of max date as 09/06/2017.
Here is my page code:
</head>
<body>
<input type="text" id="pickDate2" >
<input type="text" id="pickDate3" >
<script>
$("#pickDate2").datepicker();
$("#pickDate3").datepicker('option','maxDate',new Date());
$("#pickDate2").change(function(){
var val = $(this).val();
$("#pickDate3").datepicker('option','minDate',Date.parse(val));
})
</script>
</body>
</html>
Now, after the page loads, when the below code is executed, min date is not set
$("#pickDate2").change(function(){
var val = $(this).val();
$("#pickDate3").datepicker('option','minDate',09/03/2017);
})
When, I check the console for my plugin override code, the parameters seem to be fine.
console.log(_options);//Object { changeYear: true, changeMonth: true, minDate: Date 2017-09-03T18:15:00.000Z }
As far as I know, the JavaScript call function is not executing the second time. I couldn't find anything concrete since I searched the web for it. I want the plugin to accept parameters the second time as well.
#pickDate3.$("#pickDate3").datepicker('option','maxDate',new Date());is a method call, not an initialization. It's ignored if you do it on an element that has never had a datepicker initialized on it.