javascript - endDate showing as Invalid Date using Daterangepicker -
i using daterangepicker select startdate , enddate. startdate works fine enddate shows invalid date.
here code:
var dateformat = "d mmm yyyy"; var displaydate = function() { var dateformat = "d mmm yyyy"; var begin = moment($("#add-start-date").val()); var end = moment($("#add-end-date").val()); if( begin !== null && end !== null ) { $("#add-start-date").parent().removeclass("hidden"); $("#add-start-date").parent().siblings().removeclass("hidden"); } else if( begin !== null ) { $("#add-start-date").parent().removeclass("hidden"); $("#add-start-date").parent().siblings().addclass("hidden"); } if (begin !== null){ $("#add-start-date").html(begin.format(dateformat)); } if (end !== null){ $("#add-end-date").html(end.format(dateformat)); } $("#add-when-results").removeclass("hidden"); // $(".facet-when h5").hide(); if( begin === null && end === null) { $("#add-when-results").addclass("hidden"); $(".facet-when h5").show(); } }; $(function(){ $(".facet-when").daterangepicker({ format: dateformat, locale: { fromlabel: 'from', tolabel: 'to' }, parentel: "#mem-add-overlay .facet-when" }, function(start, end) { var begin_string = ""; var end_string = ""; if( start !== null ) { begin_string = start.format("yyyy-mm-dd"); } if( end !== null ) { end_string = end.format("yyyy-mm-dd"); } $("#add-start-date").val(begin_string); if( begin_string === end_string ) { $("#add-end-date").val(""); } else { $("#add-end-date").val(end_string); } displaydate(); }); });
html line:
<input id="id_add-when" maxlength="100" name="add-when" type="hidden">
when clicking input field, opens calendar. startdate current day date , enddate same. if directly click apply button, startdate takes fine enddate returns invaliddate. again if select enddate enddate takes fine..
any suggessions please
Comments
Post a Comment