I have a client side check that checks that EndDate greater than or equal to StartDate . Validation works, but it does not work as I would like. I would like it to work as soon as the date has been selected on the datepicker for EndDate . How can i do this? I tried the following:
Date Code:
$(".datepicker").datepicker({ changeMonth: true, changeYear: true, onClose: function () { $(this).focusout(); } });
Security Code:
$("#EndDate").focusout(function () { jQuery.validator.addMethod('datetimegreaterthanorequal', function (value, element, params) { var startDateValue = $(params.element).val(); return Date.parse(value) >= Date.parse(startDateValue); }, ''); jQuery.validator.unobtrusive.adapters.add('datetimegreaterthanorequal', ['startdate'], function (options) { var prefix = options.element.name.substr(0, options.element.name.lastIndexOf('.') + 1), other = options.params.startdate, fullOtherName = appendModelPrefix(other, prefix), element = $(options.form).find(':input[name=' + fullOtherName + ']')[0]; options.rules['datetimegreaterthanorequal'] = { element: element }; if (options.message) { options.messages['datetimegreaterthanorequal'] = options.message; } }); function appendModelPrefix(value, prefix) { if (value.indexOf('*.') === 0) { value = value.replace('*.', prefix); } return value; } })
The vanilla thrilla
source share