0

I have two input fields on a webpage for a Start Date and an End Date and I am using kendo validation to ensure they are formatted properly; and that the End Date is greater than or equal to the Start Date. I have used the data-greaterdate-field attribute to successfully ensure that the End Date is greater than the Start Date; but what I really need is to ensure that it is greater than or equal to the Start Date. The data-greaterdate-field attribute corresponds to

validationtype = greaterdate

Is there a validationtype for greater than or equal to?

Here is sample of the code:

<input id="startdate" name="Start Date">
<input id="enddate" name="End Date" data-greaterdate-field="Start Date" data-greaterdate-msg='End date should be after start date'>
4

1 回答 1

0

将此处理到 Kendo Validator 的规则部分。

function initializeValidator(){          
return $('#FormElement').kendoValidator({  
    rules: {        
     greaterdate: function (input) {        
      if (input.is('[data-greaterdate-msg]') && input.val() != "") {                                            
            var date = kendo.parseDate(input.val()),
            otherDate = kendo.parseDate($("[name='" + input.data('greaterdateField') +  "']").val());        
    return otherDate == null || otherDate.getTime() <= date.getTime();        
  }        
  return true;        
} 

注意:“<=”在规则部分中起作用。我用的是剑道版本 2016.1.412

于 2016-09-16T02:16:08.627 回答