From 87285d2b962ad257dc4b12ac68914a161f4609ae Mon Sep 17 00:00:00 2001 From: Yvonne Yip Date: Tue, 5 May 2015 15:11:50 -0700 Subject: [PATCH 1/2] implement iron-validatable-behavior --- .gitignore | 1 + README.md | 1 + bower.json | 32 ++++++++++++++++ demo/cats-only.html | 46 +++++++++++++++++++++++ demo/index.html | 68 ++++++++++++++++++++++++++++++++++ demo/validatable-input.html | 46 +++++++++++++++++++++++ index.html | 30 +++++++++++++++ iron-validatable-behavior.html | 62 +++++++++++++++++++++++++++++++ test/index.html | 33 +++++++++++++++++ test/simple-validator.html | 26 +++++++++++++ 10 files changed, 345 insertions(+) create mode 100644 .gitignore create mode 100644 bower.json create mode 100644 demo/cats-only.html create mode 100644 demo/index.html create mode 100644 demo/validatable-input.html create mode 100644 index.html create mode 100644 iron-validatable-behavior.html create mode 100644 test/index.html create mode 100644 test/simple-validator.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d4ae25 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bower_components diff --git a/README.md b/README.md index cba2e8c..48f7fb2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # iron-validatable-behavior Implements an element validated with Polymer.IronValidatorBehavior + diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..bc068ab --- /dev/null +++ b/bower.json @@ -0,0 +1,32 @@ +{ + "name": "iron-validatable-behavior", + "version": "0.8.0", + "authors": "The Polymer Authors", + "keywords": [ + "web-components", + "web-component", + "polymer" + ], + "main": [ + "iron-validatable-behavior.html" + ], + "private": true, + "repository": { + "type": "git", + "url": "git://github.com/PolymerElements/iron-validatable-behavior.git" + }, + "license": "MIT", + "homepage": "https://github.com/PolymerElements/iron-validatable-behavior", + "ignore": [], + "dependencies": { + "polymer": "Polymer/polymer#v0.8.0-rc.7", + "iron-meta": "PolymerElements/iron-meta#^0.8.0" + }, + "devDependencies": { + "iron-component-page": "PolymerElements/iron-component-page#^0.8.0", + "iron-validator-behavior": "PolymerElements/iron-validator-behavior#^0.8.0", + "test-fixture": "PolymerElements/test-fixture#^0.8.0", + "web-component-tester": "*", + "webcomponentsjs": "Polymer/webcomponentsjs#^0.6.0" + } +} diff --git a/demo/cats-only.html b/demo/cats-only.html new file mode 100644 index 0000000..83ef9ba --- /dev/null +++ b/demo/cats-only.html @@ -0,0 +1,46 @@ + + + + + + diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..134398e --- /dev/null +++ b/demo/index.html @@ -0,0 +1,68 @@ + + + + + + + + + + iron-validatable-behavior demo + + + + + + + + + + + + + + + + + + + diff --git a/demo/validatable-input.html b/demo/validatable-input.html new file mode 100644 index 0000000..19cf477 --- /dev/null +++ b/demo/validatable-input.html @@ -0,0 +1,46 @@ + + + + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..cfaa5b1 --- /dev/null +++ b/index.html @@ -0,0 +1,30 @@ + + + + + + + + + iron-validatable-behavior + + + + + + + + + + + + + diff --git a/iron-validatable-behavior.html b/iron-validatable-behavior.html new file mode 100644 index 0000000..3f08b64 --- /dev/null +++ b/iron-validatable-behavior.html @@ -0,0 +1,62 @@ + + + + + + + + diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..4494f33 --- /dev/null +++ b/test/index.html @@ -0,0 +1,33 @@ + + + + + + paper-validatable-behavior tests + + + + + + + + + + + + + + diff --git a/test/simple-validator.html b/test/simple-validator.html new file mode 100644 index 0000000..b794ed7 --- /dev/null +++ b/test/simple-validator.html @@ -0,0 +1,26 @@ + + + + + + From 6d5312e4da82db5a23406e7257094344c64bb39c Mon Sep 17 00:00:00 2001 From: Yvonne Yip Date: Tue, 5 May 2015 16:40:18 -0700 Subject: [PATCH 2/2] add `invalid` property --- iron-validatable-behavior.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/iron-validatable-behavior.html b/iron-validatable-behavior.html index 3f08b64..9665f0f 100644 --- a/iron-validatable-behavior.html +++ b/iron-validatable-behavior.html @@ -36,6 +36,15 @@ type: String }, + /** + * True if the last call to `validate` is invalid. + */ + invalid: { + reflectToAttribute: true, + type: Boolean, + value: false + }, + _validatorMeta: { type: Object } @@ -50,11 +59,20 @@ this._validatorMeta = new Polymer.IronMeta({type: this.validatorType}); }, + /** + * Returns true if there is a validator. + */ + hasValidator: function() { + return this._validator != null; + }, + /** * Validates the value. */ validate: function(values) { - return this._validator && this._validator.validate(values); + var valid = this._validator && this._validator.validate(values); + this.invalid = !valid; + return valid; } };