Created
September 12, 2018 08:55
-
-
Save Matthew-Wise/3557e3f05dcbd8d9ee7549f37ceb8740 to your computer and use it in GitHub Desktop.
Add min date to Umbraco forms validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($) { | |
if ($.validator != undefined) { | |
$.validator.setDefaults({ | |
ignore: ":hidden" | |
}); | |
$.validator.unobtrusive.adapters.addBool("requiredcb", "required"); | |
$.validator.addMethod('umbracoforms_selectonefromlist', function(value, element) { | |
var valid = false; | |
$("input", $(element).closest(".checkboxlist, .radiobuttonlist")).each(function(i) { | |
if ($(this).is(':checked')) { | |
valid = true; | |
} | |
}); | |
return valid; | |
}); | |
$.validator.unobtrusive.adapters.addBool("requiredlist", "umbracoforms_selectonefromlist"); | |
$.validator.addMethod('umbracoforms_regex', function(value, element) { | |
var regex = $(element).attr("data-regex"); | |
var val = $(element).val(); | |
if (val.length == 0) { | |
return true; | |
} | |
return val.match(regex); | |
}); | |
$.validator.unobtrusive.adapters.addBool("regex", "umbracoforms_regex"); | |
//Custom code | |
$.validator.addMethod('umbracoforms_mindate', function(value, element) { | |
var valid = false; | |
//min date checke | |
return valid; | |
}); | |
$.validator.unobtrusive.adapters.addBool("date", "umbracoforms_mindate"); | |
//End custom code | |
$('.contour input[type=submit]').not('.cancel').click(function (evt) { | |
evt.preventDefault(); | |
var self = $(this); | |
var frm = self.closest('form'); | |
frm.validate(); | |
if (frm.valid()) { | |
frm.submit(); | |
self.attr('disabled', 'disabled'); | |
} | |
}); | |
} | |
} (jQuery)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment