jQuery Datepicker minDate getDate not working correctly -
i have 4 datepickers used record dates of paternal leave.
datepicker 1 expected due date.
datepicker 2 actual date of birth.
datepicker 3 start date of paternal leave.
datepicker 4 end date of paternal leave.
the mindate in datepicker 3 should equal greater of dates entered in datepickers 1 & 2.
the code have written appears work ok... until date in datepicker 2 spans across 2 months prior date entered in datepicker 1.
example 1: datepicker 1: 03/11/16 datepicker 2: 01/11/16 - mindate = 03/11/16 - correct.
example 2: datepicker 1: 03/11/16 datepicker 2: 30/09/16 - mindate = 30/09/16 - incorrect.
this results in mindate in datepicker 3 defaulting date entered in datepicker 2.
i need getdate method greater date either datepicker 1 or 2 , use date set mindate datepicker 3.
here code datepickers 1 – 3 code in datepicker 4 works fine.
i reckon mindate method needs tweaking , grateful if shed light on this....
// datepicker 1 $("#paternityleavedetails_paternityleave_expectedduedate").datepicker({ onclose: function(datetext, inst) { if ($(this).val()) { if ($("#paternityleavedetails_paternityleave_expectedduedate").val() > $("#paternityleavedetails_paternityleave_childsdateofbirth").val()) { var d = $(this).datepicker("getdate"); // alert(d); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "mindate", new date(d.getfullyear(),d.getmonth(),d.getdate())); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "maxdate", new date(d.getfullyear(),d.getmonth(),d.getdate()).add(56).days()); }else{ if ($("#paternityleavedetails_paternityleave_childsdateofbirth").val() > $("#paternityleavedetails_paternityleave_expectedduedate").val()) { var d = $("#paternityleavedetails_paternityleave_childsdateofbirth").datepicker("getdate"); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "mindate", new date(d.getfullyear(),d.getmonth(),d.getdate())); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "maxdate", new date(d.getfullyear(),d.getmonth(),d.getdate()).add(56).days()); } } } } }); // datepicker 2 $("#paternityleavedetails_paternityleave_childsdateofbirth").datepicker({ onclose: function(datetext, inst) { if ($(this).val()) { if ($("#paternityleavedetails_paternityleave_childsdateofbirth").val() > $("#paternityleavedetails_paternityleave_expectedduedate").val()) { var d = $(this).datepicker("getdate"); // alert(d); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "mindate", new date(d.getfullyear(),d.getmonth(),d.getdate())); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "maxdate", new date(d.getfullyear(),d.getmonth(),d.getdate()).add(56).days()); }else{ if ($("#paternityleavedetails_paternityleave_expectedduedate").val() > $("#paternityleavedetails_paternityleave_childsdateofbirth").val()) { var d = $("#paternityleavedetails_paternityleave_expectedduedate").datepicker("getdate"); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "mindate", new date(d.getfullyear(),d.getmonth(),d.getdate())); $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker("option", "maxdate", new date(d.getfullyear(),d.getmonth(),d.getdate()).add(56).days()); } } } } }); //datepicker 3 $("#paternityleavedetails_paternityleave_paternityleavestartdate").datepicker({ onclose: function(datetext, inst) { if ($(this).val()) { var d = $(this).datepicker("getdate"); $("#paternityleavedetails_paternityleave_paternityleaveenddate").datepicker("option", "mindate", new date(d.getfullyear(),d.getmonth(),d.getdate()).add(1).weeks().add(-1).days()); $("#paternityleavedetails_paternityleave_paternityleaveenddate").datepicker("option", "maxdate", new date(d.getfullyear(),d.getmonth(),d.getdate()).add(2).weeks().add(-1).days()); $("#paternityleavedetails_paternityleave_paternityleaveenddate").datepicker("setdate", null); } } });
Comments
Post a Comment