Skip to content

Commit

Permalink
Modified FormValidator.prototype._validateField() to support allowing
Browse files Browse the repository at this point in the history
custom messaging on a per field/rule basis. For instance, you can now
use the following syntax to target applying a unique validation error
messaging to the field `fieldName` when it fails `required`:

```js
// initiate validator with single required rule
var validator = new FormValidator(
    'form-identifier',
        { name: 'fieldName', display: 'your field name', rules:
	'required' },
	    function(errors, evt) { }
	    );

	    // set custom error message display for fieldName input
	    // field and required rule
	    validator.setMessage('fieldName.required', 'This field is
	    required, yo');
	    ```

	    When using `setMessage()`, the newly supported format is
	    `fieldName`.`validationRule`. This allows you to uniquely
	    target individual field/rule combos for error messaging.
	    Very useful if you want to give more instruction/detail to a
	    user.

	    This scratches my itch for overriding messaging on a low
	    level. Hope others find this helpful!
  • Loading branch information
cballou committed Mar 14, 2014
1 parent e4830be commit c302d90
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@

if (failed) {
// Make sure we have a message for this rule
var source = this.messages[method] || defaults.messages[method],
var source = this.messages[field.name + '.' + method] || this.messages[method] || defaults.messages[method],
message = 'An error has occurred with the ' + field.display + ' field.';

if (source) {
Expand Down

0 comments on commit c302d90

Please sign in to comment.