diff --git a/bower.json b/bower.json index 2ebf2bc..2aa7b77 100644 --- a/bower.json +++ b/bower.json @@ -25,9 +25,19 @@ "devDependencies": { "paper-styles": "PolymerElements/paper-styles#^1.0.4", "iron-component-page": "PolymerElements/iron-component-page#^1.0.0", - "iron-validator-behavior": "PolymerElements/iron-validator-behavior#^1.0.0", + "iron-validator-behavior": "https://github.com/tlouisse/iron-validator-behavior.git#feature/multipleValidators", + "paper-input": "https://github.com/tlouisse/paper-input.git#feature/multipleValidators", + "iron-input": "https://github.com/tlouisse/iron-input.git#feature/multipleValidators", + "paper-dialog": "PolymerElements/paper-dialog#^1.0.0", + "paper-icon-button": "PolymerElements/paper-icon-button#^1.0.0", "test-fixture": "PolymerElements/test-fixture#^1.0.0", "web-component-tester": "^4.0.0", "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" } } diff --git a/demo/index.html b/demo/index.html index 84b96a8..7521c63 100644 --- a/demo/index.html +++ b/demo/index.html @@ -20,10 +20,15 @@ - + + + + + + - + + + + +
+ +
+ +

Multiple validators

+ +

+ Scenario: add an animal with at least two characters, but cats and catfishes are not allowed. +

+ +

Before

+ + + + + + + + + + View sources + + + +

Before: sources

+ +

Javascript

+
+window.addEventListener('WebComponentsReady', function () {
+    var input = document.getElementById('before').$.input;
+    var validator = document.getElementById('combinedValidator');
+    var scope = document.getElementById('scope');
+
+    scope.msg = 'Make sure this field is not empty and contains at least two characters. Cats and catfishes are not allowed.';
+    input.addEventListener('iron-input-validate', function setErrorMessage() {
+        if (input.validity.valueMissing) {
+            scope.msg = 'Please fill in this field';
+        } else if (input.validity.patternMismatch) {
+            scope.msg = 'Use at least two characters';
+            // Note the custom validator can only be assigned to one input when using it to store state of sub validators.
+        } else if (!validator.validState.noCats) {
+            scope.msg = 'No cat(s) allowed';
+        } else if (!validator.validState.noCatfishes) {
+            scope.msg = 'No cat(fish(es)) allowed';
+        }
+    });
+});
+
+ +

HTML

+ + +
+<no-cats-or-catfishes id="combinedValidator"></no-cats-or-catfishes>
+
+<paper-input id="before" label="Your favorite animal (*)" auto-validate
+    validator="no-cats-or-catfishes" required pattern=".{2,}"
+    error-message="[[msg]]">
+</paper-input>
+
+ + +

External validator

+ +

See 'no-cats-or-catfishes.html' ...

+ +
+ Close +
+
+ +

After

+ + + +

+ (Note that no-cats has a higher priority than no-catfishes and its error message will therefore take + precedence over that of no-catfishes) +

+ + + + + + View sources + + + +

After: sources

+ +

HTML

+
<paper-input id="after" label="Your favorite animal (*)" auto-validate
+    validator="required pattern no-cats no-catfishes" required pattern=".{2,}">
+</paper-input>
+
+ +

Native messages configuration

+ +

See 'native-validators-config.html'(this configuration is needed once on a global level) ...

+ +
+ Close +
+ +
+
+ +
+ + + + + diff --git a/demo/old-vs-new/native-validators-config.html b/demo/old-vs-new/native-validators-config.html new file mode 100644 index 0000000..511920d --- /dev/null +++ b/demo/old-vs-new/native-validators-config.html @@ -0,0 +1,21 @@ + + + + + + + + diff --git a/demo/old-vs-new/no-cats-or-catfishes.html b/demo/old-vs-new/no-cats-or-catfishes.html new file mode 100644 index 0000000..9d8bbbc --- /dev/null +++ b/demo/old-vs-new/no-cats-or-catfishes.html @@ -0,0 +1,63 @@ + + + + + + + + + + + + + diff --git a/demo/cats-only.html b/demo/validators/cats-only.html similarity index 88% rename from demo/cats-only.html rename to demo/validators/cats-only.html index 83ef9ba..c88ea45 100644 --- a/demo/cats-only.html +++ b/demo/validators/cats-only.html @@ -8,8 +8,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> - - + + diff --git a/demo/validators/no-cats.html b/demo/validators/no-cats.html new file mode 100644 index 0000000..ff9b4ed --- /dev/null +++ b/demo/validators/no-cats.html @@ -0,0 +1,37 @@ + + + + + + diff --git a/iron-validatable-behavior.html b/iron-validatable-behavior.html index 803731b..1c9dda9 100644 --- a/iron-validatable-behavior.html +++ b/iron-validatable-behavior.html @@ -12,10 +12,14 @@ diff --git a/test/index.html b/test/index.html index 605c95a..833e8fc 100644 --- a/test/index.html +++ b/test/index.html @@ -23,7 +23,9 @@ /* no tests */ WCT.loadSuites([ 'iron-validatable-behavior.html', - 'iron-validatable-behavior.html?dom=shadow' + 'iron-validatable-behavior-automatic-instances.html', + 'iron-validatable-behavior.html?dom=shadow', + 'iron-validatable-behavior-automatic-instances.html?dom=shadow' ]); diff --git a/test/iron-validatable-behavior-automatic-instances.html b/test/iron-validatable-behavior-automatic-instances.html new file mode 100644 index 0000000..99211be --- /dev/null +++ b/test/iron-validatable-behavior-automatic-instances.html @@ -0,0 +1,56 @@ + + + + + + iron-validatable-behavior tests + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/iron-validatable-behavior.html b/test/iron-validatable-behavior.html index a8040ef..e9d1b46 100644 --- a/test/iron-validatable-behavior.html +++ b/test/iron-validatable-behavior.html @@ -24,8 +24,13 @@ - - + + + + + + + @@ -44,6 +49,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/native-validators-config.html b/test/native-validators-config.html new file mode 100644 index 0000000..ef23221 --- /dev/null +++ b/test/native-validators-config.html @@ -0,0 +1,64 @@ + + + + + + + + + + + + + diff --git a/test/cats-only.html b/test/validators/cats-only.html similarity index 52% rename from test/cats-only.html rename to test/validators/cats-only.html index f166993..66c9e74 100644 --- a/test/cats-only.html +++ b/test/validators/cats-only.html @@ -8,23 +8,30 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> - - + + diff --git a/test/dogs-only.html b/test/validators/dogs-only.html similarity index 52% rename from test/dogs-only.html rename to test/validators/dogs-only.html index 1b462a4..b392526 100644 --- a/test/dogs-only.html +++ b/test/validators/dogs-only.html @@ -8,23 +8,30 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> - - + + diff --git a/test/validators/no-catfishes.html b/test/validators/no-catfishes.html new file mode 100644 index 0000000..9e2c66f --- /dev/null +++ b/test/validators/no-catfishes.html @@ -0,0 +1,37 @@ + + + + + + diff --git a/test/validators/no-cats.html b/test/validators/no-cats.html new file mode 100644 index 0000000..e840c3e --- /dev/null +++ b/test/validators/no-cats.html @@ -0,0 +1,37 @@ + + + + + +