jQuery Goodness Examples


Goodness is a light jQuery form validation plugin. There are no included validation rules*, feedback markup or error styles. Instead, you make the rules and use the names as classes in your own markup. When the form is validated, classes will be added or removed from your markup to match your defined styles and animation.

*A 'required' rule is provided by default, but may be overridden.

Basic Demo

goodness = $('#basic-demo').goodness();

Call the goodness method on a jQuery selector that returns a form element to intialize the plugin on that form. The only built in validation rule is 'required'. Without specifiying any other options, you can utilize that for text input fields.

Custom Rules

goodness = $('#custom-rules').goodness({ rules: { 'valid-password': function(val, $elm, $form) { return $.trim(val).length > 5; }, 'match-password': function(val, $elm, $form) { return val === $('input[name=valid-password').val(); }, 'must-check': function(val, $elm, $form) { return $elm.is(':checked'); } } });

Specify your validation rules in the 'rules' option when initializing the plugin. The name of your rule should be the same as the class name you apply to elements in your form that you want to adhear to the rule. The name of the rule should be a key in the rules object, while it's value should be a function that returns a boolean value. This function will be called to validate the input element, and will be passed the element's value, and jQuery references to the element itself as well as the form.