Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: third_party/polymer/v1_0/components/iron-form/iron-form.html

Issue 1187823002: Update Polymer components and re-run reproduce.sh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}
});
« no previous file with comments | « third_party/polymer/v1_0/components/iron-form/bower.json ('k') | third_party/polymer/v1_0/components/iron-icon/.bower.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698