Hi all, this is a column in my jqgrid: it’s a date colum and I’, editing the row via form editing. It was working fine until I added this custom validation, which now provokes a date range validation I can’t manage.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
name: 'LiveFromDate', index: 'LiveFromDate', width: 230, align: 'Left', editable: true, editrules: { custom: true, custom_func: dateCheck }, editoptions: { closeAfterEdit: true, defaultValue: moment(), size: 20, maxlengh: 10, dataInit: function (element) { moment.locale(navigator.language); $(element).datetimepicker({ dateFormat: moment.localeData().longDateFormat('L').toLowerCase().replace("yyyy", "yy"), timeFormat: moment.localeData().longDateFormat('LT').replace("A", "tt"), constrainInput: false, showOn: 'button', buttonText: '...', controlType: 'select', oneLine: true, onClose: function () { function isDonePressed() { return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1); } if (isDonePressed()) { $("#LiveFromDate").removeAttr('disabled') .removeClass("ui-state-disabled"); $('#checkActivateNow').removeAttr('checked').button('refresh'); var rowId = $("#_templateGrid").jqGrid('getGridParam', 'selrow'); $("#_templateGrid").jqGrid('setCell', rowId, "ActivateDateNow", "false"); $("#_templateGrid").jqGrid('getLocalRow', rowId).ActivateDateNow = "false"; $("#ActivateDateNow").removeAttr("checked", ""); } }, formatter: liveDateFormatter, unformatter: liveDateUnformatter }); var p = $(element).parent(); p.find("button").button(); var tb = p.parents("tbody"); tb.append('<tr class="FormData" id="tr_activate_button">' + '<td class="CaptionTD"/>' + '<td class="DataTD">&amp;nbsp;' + '<input type="checkbox" name="checkActivateNow" id="checkActivateNow"/>' + '<label for="checkActivateNow">Activate Now</label>' + '</td>' + '</tr>' ); setTimeout(function () { $("#checkActivateNow").button(); $("#checkActivateNow").off("click").on("click", function () { var rowId = $("#_templateGrid").jqGrid('getGridParam', 'selrow'); var rowData = $("#_templateGrid").getRowData(rowId); if ($(this).siblings("label").attr("aria-pressed") === "false") { $("#LiveFromDate").removeAttr('disabled', 'disabled') .removeClass("ui-state-disabled"); if (rowData.ActivateDateNow !== "false") { $("#_templateGrid").jqGrid('setCell', rowId, "ActivateDateNow", "false"); $("#_templateGrid").jqGrid('getLocalRow', rowId).ActivateDateNow = "false"; $("#ActivateDateNow").removeAttr("checked", ""); } } else { $("#LiveFromDate").val(window.dateNowText) .attr('disabled', 'disabled') .addClass("ui-state-disabled"); if (rowData.ActivateDateNow !== "true") { $("#_templateGrid").jqGrid('setCell', rowId, "ActivateDateNow", "true"); $("#_templateGrid").jqGrid('getLocalRow', rowId).ActivateDateNow = "true"; $("#ActivateDateNow").attr("checked", "checked"); } else { rowData.LiveFromDate = window.dateDefault; $("#_templateGrid").jqGrid('setCell', rowId, "LiveFromDate", rowData.LiveFromDate); $("#_templateGrid").jqGrid('setCell', rowId, "ActivateDateNow", "false"); } } }); ///blocks key strokes on the date field $("#LiveFromDate").off("keydown").on("keydown", function () { return false; }); }, 0); }, }, &nbsp; the validation function is: function dateCheck(value, caption) { if (value === window.dateNowText) { return [true]; } const now = moment(new Date()); //We need to create dates using UTC, as they are deprecated in moment: https://github.com/moment/moment/issues/1407 const dateSplit = value.match(/(\d*)\/(\d*)\/(\d*) (\d*):(\d*)/); const constructedUtc = dateSplit[3] + "-" + dateSplit[2] + "-" + dateSplit[1] + "T" + dateSplit[4] + ":" + dateSplit[5] + ":00Z"; const publishTime = moment(new Date(constructedUtc)); const diff = publishTime.diff(now, 'minutes'); if (diff < 0) { return [false, caption + ": Date must be either the current or a future date"]; } return [true, ""]; } |
which is passing ok, but something AFTER mi validation passing is coming back with this:
Date must be equal or greater than today
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top