jquery validate check at least one checkbox

Example from https://github.com/ffmike/jquery-validate <label for=”spam_email”> <input type=”checkbox” class=”checkbox” id=”spam_email” value=”email” name=”spam[]” validate=”required:true, minlength:2″ /> Spam via E-Mail </label> <label for=”spam_phone”> <input type=”checkbox” class=”checkbox” id=”spam_phone” value=”phone” name=”spam[]” /> Spam via Phone </label> <label for=”spam_mail”> <input type=”checkbox” class=”checkbox” id=”spam_mail” value=”mail” name=”spam[]” /> Spam via Mail </label> <label for=”spam[]” class=”error”>Please select at least two types of spam.</label> The … Read more

ASP .NET MVC Disable Client Side Validation at Per-Field Level

I’m not sure if this solution works on MVC3. It surely works on MVC4: You can simply disable client side validation in the Razor view prior to render the field and re-enable client side validation after the field has been rendered. Example: <div class=”editor-field”> @{ Html.EnableClientValidation(false); } @Html.TextBoxFor(m => m.BatchId, new { @class = “k-textbox” … Read more

How can I use jQuery validation with the “chosen” plugin?

jQuery validate ignores the hidden element, and since the Chosen plugin adds visibility:hidden attribute to the select, try: $.validator.setDefaults({ ignore: “:hidden:not(select)” }) //for all select OR $.validator.setDefaults({ ignore: “:hidden:not(.chosen-select)” }) //for all select having class .chosen-select Add this line just before validate() function. It works fine for me.

jQuery Validate – require at least one field in a group to be filled

That’s an excellent solution Nathan. Thanks a lot. Here’s a way making the above code work, in case someone runs into trouble integrating it, like I did: Code inside the additional-methods.js file: jQuery.validator.addMethod(“require_from_group”, function(value, element, options) { …// Nathan’s code without any changes }, jQuery.format(“Please fill out at least {0} of these fields.”)); // “filone” … Read more

jquery.validate.unobtrusive not working with dynamic injected elements

I tried Xhalent’s approach but unfortunately it wasn’t working for me. Robin’s approach did work and didn’t work. It worked great for dynamically added elements, but if you tried to use JQuery to remove all the validation attributes and spans from the DOM, the validation library still would try to validate them. However, if you … Read more

how to check if a form is valid programmatically using jQuery Validation Plugin

Use .valid() from the jQuery Validation plugin: $(“#form_id”).valid(); Checks whether the selected form is valid or whether all selected elements are valid. validate() needs to be called on the form before checking it using this method. Where the form with id=’form_id’ is a form that has already had .validate() called on it.

Validate that end date is greater than start date with jQuery

Just expanding off fusions answer. this extension method works using the jQuery validate plugin. It will validate dates and numbers jQuery.validator.addMethod(“greaterThan”, function(value, element, params) { if (!/Invalid|NaN/.test(new Date(value))) { return new Date(value) > new Date($(params).val()); } return isNaN(value) && isNaN($(params).val()) || (Number(value) > Number($(params).val())); },’Must be greater than {0}.’); To use it: $(“#EndDate”).rules(‘add’, { greaterThan: … Read more

Bootstrap with jQuery Validation Plugin

for total compatibility with twitter bootstrap 3, I need to override some plugins methods: // override jquery validate plugin defaults $.validator.setDefaults({ highlight: function(element) { $(element).closest(‘.form-group’).addClass(‘has-error’); }, unhighlight: function(element) { $(element).closest(‘.form-group’).removeClass(‘has-error’); }, errorElement: ‘span’, errorClass: ‘help-block’, errorPlacement: function(error, element) { if(element.parent(‘.input-group’).length) { error.insertAfter(element.parent()); } else { error.insertAfter(element); } } }); See Example: http://jsfiddle.net/mapb_1990/hTPY7/7/