MVC3 Validation – Require One From Group

Here’s one way to proceed (there are other ways, I am just illustrating one that would match your view model as is): [AttributeUsage(AttributeTargets.Property)] public class RequireAtLeastOneOfGroupAttribute: ValidationAttribute, IClientValidatable { public RequireAtLeastOneOfGroupAttribute(string groupName) { ErrorMessage = string.Format(“You must select at least one value from group \”{0}\””, groupName); GroupName = groupName; } public string GroupName { get; … Read more

jQuery multiple input name[] validation

The jQuery Validate plugin will not allow you to validate multiple input elements with the same name. You must have a unique name on each. There is no workaround; the name attribute is how the plugin internally keeps track of all form inputs. <input type=”text” placeholder=”” class=”m-wrap span12″ name=”test[1]”> <input type=”text” placeholder=”” class=”m-wrap span12″ name=”test[2]”> … Read more

Validate inputs that are not inside a form with jQuery Validation plugin [closed]

The previously accepted answer (since deleted) was linking to a plugin that was last updated in January 2009. This obsolete plugin is very different than the plugin the OP was asking about: Title: “Validate inputs that are not inside a form with jQuery Validation plugin“ Tag: jquery-validate Using the jQuery Validate plugin, you cannot validate … Read more

validation for at least one checkbox

Working demo http://jsfiddle.net/RGUTv/ Updated – 12 Jan 2015 => http://jsfiddle.net/r24kcvz6/ CDN was cahnged http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js – you can replicate the behaviour by deselcting all the checkboxes and clicking on the submit button. http://jqueryvalidation.org/#latest-files-on-jsdelivr-cdn-%28hotlinking-welcome%29: code $.validator.addMethod(‘require-one’, function(value) { return $(‘.require-one:checked’).size() > 0; }, ‘Please check at least one box.’); var checkboxes = $(‘.require-one’); var checkbox_names = $.map(checkboxes, … Read more

How to include JavaScript files by h:outputScript? [duplicate]

The <h:outputScript> (and <h:outputStylesheet>) loads resources from /resources folder. You need to put the scripts in that folder. WebContent |– resources | `– js | |– jquery-1.6.2.js | |– myapp.validate.js | |– jquery.validate.js | `– jquery.maskedinput.js |– WEB-INF : Then the following script declarations should work: <h:outputScript name=”js/jquery-1.6.2.js” /> <h:outputScript name=”js/jquery.validate.js” /> <h:outputScript name=”js/jquery.maskedinput.js” /> … Read more