Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
changed error attr from 'name' to 'validator'
Browse files Browse the repository at this point in the history
added resolutions

documentation error message markup

added resolution

demo page name
  • Loading branch information
tlouisse committed Sep 8, 2016
1 parent f1459c3 commit b80407f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
},
"resolutions": {
"paper-input": "feature/multipleValidators",
"iron-validator-behavior": "feature/multipleValidators",
"iron-input": "feature/multipleValidators",
"iron-validatable-behavior": "feature/multipleValidators"
}
}
2 changes: 1 addition & 1 deletion demo/old-vs-new/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>tgc-forms Demo</title>
<title>Multiple validators - Before and after</title>
<script src="../../../webcomponentsjs/webcomponents-lite.min.js"></script>

<link rel="stylesheet" href="../../../prism/themes/prism.css">
Expand Down
13 changes: 7 additions & 6 deletions iron-validatable-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@

/**
* Array holding error objects for the current state of the validatable element.
* Each error has the following format:
* {Object} error
* {string} error.name -- validator name of custom validator instance with IronValidatorBehavior
* {string} error.message -- message that is assigned to the validator instance
* {number} error.priority -- priority of the error message, based on order supplied in validator property
* Each error has the following keys:
* <ul>
* <li><b>validator</b> (String) : name of custom validator instance with IronValidatorBehavior</li>
* <li><b>message</b> (String) : message that is assigned to the validator instance</li>
* <li><b>priority</b> (Number) : priority of the error message, based on order supplied in validator property</li>
* </ul>
*/
errors: {
type: Array,
Expand Down Expand Up @@ -183,7 +184,7 @@
for (var v in this._validator) {
if (!this._validator[v].validate(value, this)) {
this.push('errors', {
name: this._validator[v].validatorName,
validator: this._validator[v].validatorName,
message: this._validator[v].message,
priority: index
});
Expand Down
20 changes: 10 additions & 10 deletions test/iron-validatable-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@
var validatable = fixture('multipleValidators')[2];
validatable.validate('cat');
assert.equal(validatable.errors.length, 2);
assert.equal(validatable.errors[0].name, 'no-cats');
assert.equal(validatable.errors[0].validator, 'no-cats');
assert.equal(validatable.errors[0].message, 'No cat(s) allowed');
assert.equal(validatable.errors[0].priority, 0);
assert.equal(validatable.errors[1].name, 'no-catfishes');
assert.equal(validatable.errors[1].validator, 'no-catfishes');
assert.equal(validatable.errors[1].message, 'No cat(fish(es)) allowed');
assert.equal(validatable.errors[1].priority, 1);
});
Expand All @@ -215,13 +215,13 @@
validatable.value = '';
validatable.validate();

assert.equal(validatable.errors[0].name, 'required');
assert.equal(validatable.errors[0].validator, 'required');
assert.equal(validatable.errors[0].priority, 0);

assert.equal(validatable.errors[1].name, 'cats-only');
assert.equal(validatable.errors[1].validator, 'cats-only');
assert.equal(validatable.errors[1].priority, 1);

assert.equal(validatable.errors[2].name, 'dogs-only');
assert.equal(validatable.errors[2].validator, 'dogs-only');
assert.equal(validatable.errors[2].priority, 2);
});

Expand All @@ -230,17 +230,17 @@
validatable.value = '2';
validatable.validate();

assert.equal(validatable.errors[0].name, 'min');
assert.equal(validatable.errors[0].validator, 'min');
assert.equal(validatable.errors[0].priority, 0);
assert.equal(validatable.errors[1].name, 'step');
assert.equal(validatable.errors[1].validator, 'step');
assert.equal(validatable.errors[1].priority, 1);
});

test('native validators can contain custom messages', function() {
var validatable = fixture('override-native-messages').querySelector('[min]');
validatable.validate();

assert.equal(validatable.errors[0].name, 'min');
assert.equal(validatable.errors[0].validator, 'min');
assert.equal(validatable.errors[0].message, 'customMin');
});

Expand All @@ -264,7 +264,7 @@

validatable.validate();

assert.equal(validatable.errors[0].name, validator, 'Validator [' + validator + '] is not triggered');
assert.equal(validatable.errors[0].validator, validator, 'Validator [' + validator + '] is not triggered');
assert.equal(validatable.errors[0].message, msg, 'Validation message for validator [' + validator + '] is not set properly');
});
});
Expand All @@ -280,7 +280,7 @@

validatable.validate();

assert.equal(validatable.errors[0].name, validator, 'Validator [' + validator + '] is not triggered');
assert.equal(validatable.errors[0].validator, validator, 'Validator [' + validator + '] is not triggered');
assert.equal(validatable.errors[0].message, msg, 'Validation message for validator [' + validator + '] is not set properly');
});
});
Expand Down

0 comments on commit b80407f

Please sign in to comment.