| Index: third_party/polymer/v1_0/components/iron-form/iron-form.html
|
| diff --git a/third_party/polymer/v1_0/components/iron-form/iron-form.html b/third_party/polymer/v1_0/components/iron-form/iron-form.html
|
| index 44b77ae86f73fb504835097109ca1e9871f4c9d2..ec378c8df45fd18d2099d8c805dd34499c24bb90 100644
|
| --- a/third_party/polymer/v1_0/components/iron-form/iron-form.html
|
| +++ b/third_party/polymer/v1_0/components/iron-form/iron-form.html
|
| @@ -39,7 +39,7 @@ call the form's `submit` method.
|
| function submitForm() {
|
| document.getElementById('form').submit();
|
| }
|
| -
|
| +
|
| @demo demo/index.html
|
| */
|
|
|
| @@ -50,6 +50,12 @@ call the form's `submit` method.
|
| extends: 'form',
|
|
|
| /**
|
| + * Fired if the form cannot be submitted because it's invalid.
|
| + *
|
| + * @event iron-form-invalid
|
| + */
|
| +
|
| + /**
|
| * Fired after the form is submitted.
|
| *
|
| * @event iron-form-submit
|
| @@ -69,7 +75,7 @@ call the form's `submit` method.
|
|
|
| listeners: {
|
| 'iron-form-element-register': '_registerElement',
|
| - 'submit': 'submit'
|
| + 'submit': '_onSubmit'
|
| },
|
|
|
| ready: function() {
|
| @@ -85,9 +91,14 @@ call the form's `submit` method.
|
| /**
|
| * Called to submit the form.
|
| */
|
| - submit: function(event) {
|
| - if (!this._validate()) {
|
| - return false;
|
| + submit: function() {
|
| + if (!this.noValidate && !this._validate()) {
|
| +
|
| + // In order to trigger the native browser invalid-form UI, we need
|
| + // to do perform a fake form submit.
|
| + this._doFakeSubmitForValidation();
|
| + this.fire('iron-form-invalid');
|
| + return;
|
| }
|
|
|
| var json = this.serialize();
|
| @@ -102,6 +113,10 @@ call the form's `submit` method.
|
|
|
| this._requestBot.generateRequest();
|
| this.fire('iron-form-submit', json);
|
| + },
|
| +
|
| + _onSubmit: function(event) {
|
| + this.submit();
|
|
|
| // Don't perform a page refresh.
|
| if (event) {
|
| @@ -171,9 +186,25 @@ call the form's `submit` method.
|
|
|
| _validate: function() {
|
| var valid = true;
|
| +
|
| + // Validate all the custom elements.
|
| + var validatable;
|
| for (var el, i = 0; el = this._customElements[i], i < this._customElements.length; i++) {
|
| - valid = el.validate() && valid;
|
| + if (el.required) {
|
| + validatable = /** @type {{validate: (function() : boolean)}} */ (el);
|
| + valid = validatable.validate() && valid;
|
| + }
|
| }
|
| +
|
| + // Validate the form's native elements.
|
| + for (var el, i = 0; el = this.elements[i], i < this.elements.length; i++) {
|
| + // Custom elements that extend a native element will also appear in
|
| + // this list, but they've already been validated.
|
| + if (!el.hasAttribute('is') && el.willValidate && el.checkValidity) {
|
| + valid = el.checkValidity() && valid;
|
| + }
|
| + }
|
| +
|
| return valid;
|
| },
|
|
|
| @@ -184,6 +215,17 @@ call the form's `submit` method.
|
| } else {
|
| return el.checked;
|
| }
|
| + },
|
| +
|
| + _doFakeSubmitForValidation: function() {
|
| + var fakeSubmit = document.createElement('input');
|
| + fakeSubmit.setAttribute('type', 'submit');
|
| + fakeSubmit.style.display = 'none';
|
| + this.appendChild(fakeSubmit);
|
| +
|
| + fakeSubmit.click();
|
| +
|
| + this.removeChild(fakeSubmit);
|
| }
|
|
|
| });
|
|
|