From 7f926aaa5d16381ac8ddff04ed7f68ad557f7689 Mon Sep 17 00:00:00 2001 From: Elliott Marquez Date: Wed, 9 May 2018 13:15:41 -0700 Subject: [PATCH] auto-converted by polymer-modulizer --- .travis.yml | 23 +- bower.json | 71 -- demo/{cats-only.html => cats-only.js} | 56 +- demo/index.html | 203 +++- index.html | 6 +- iron-form.d.ts | 151 --- iron-form.html | 618 ----------- iron-form.js | 619 +++++++++++ manifest.json | 32 + package.json | 38 +- test/basic.html | 1405 +++++++++++++------------ test/index.html | 2 +- test/slotted.html | 316 +++--- 13 files changed, 1746 insertions(+), 1794 deletions(-) delete mode 100644 bower.json rename demo/{cats-only.html => cats-only.js} (50%) delete mode 100644 iron-form.d.ts delete mode 100644 iron-form.html create mode 100644 iron-form.js create mode 100644 manifest.json diff --git a/.travis.yml b/.travis.yml index 8adbf2d..d1827c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,20 +2,12 @@ language: node_js sudo: required before_script: - npm install -g polymer-cli - - polymer install --variants - - >- - npm run update-types && git diff --exit-code || (echo -e - '\n\033[31mERROR:\033[0m Typings are stale. Please run "npm run - update-types".' && false) - - >- - npm run format && git diff --exit-code || (echo -e '\n\033[31mERROR:\033[0m - Typings are stale. Please run "npm run format".' && false) + - 'npm run update-types && git diff --exit-code || (echo -e ''\n\033[31mERROR:\033[0m Typings are stale. Please run "npm run update-types".'' && false)' + - 'npm run format && git diff --exit-code || (echo -e ''\n\033[31mERROR:\033[0m Typings are stale. Please run "npm run format".'' && false)' env: global: - - secure: >- - JeSfmBNQGyT7fu9NURSHqK9miBYrieoVdCnzOIq1QRDpWEiUGJKrcWKbabA/1MrlYfbQDFwXIDGrv0hcZzf0xbDblo5s/jUnep1vq/w/IRznEDnhJelpjG6c38vlBbPQOZI3L32eu8w5BBmlXhc4XXpUGkIy94O1Iz7Tn3zkeFI/fKhMyrmgDUOuehP0EHyoKxLCyWGLV+aTRtif6TK/wn6ULwM+GvLiS7nykrnA2WoDEECAuCoIsfR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cJ4H5dtI/HHaAQTmeT3JpvTfz5f9dvAuJVqimQOzdFlKM7ehhNk3j9KtED/vnQW9+0AJhOT9+7trokW++jl219QS29FOPYTxSo/XvI6iLZfOr4X0l4VhNkgHeE6EyCUoGNwDRxUvn+KcsQMk6JdHLY+lCckZ+tRFQIUjMPqjn9tB/MjBqtXxDhF5ZjaOcLufzuywKBzlMT4OkAiOGK9qFENKpTVaqvmRPPM1bjkZuzfTBJTOzWDznf2V4r65/s6ZRpoqEy0ozb7NjUEjYOR+OuZfKYVwT5VmAykKLNW3eQJc1zJjvhjghSIxOWH9AvD18UeQtEcv2J5pVFIp+BFVR25i0BH+efOwWJ49hk0o0N+Dw= node_js: stable addons: firefox: latest @@ -26,8 +18,7 @@ addons: - google-chrome-stable sauce_connect: true script: - - xvfb-run polymer test - - >- - if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then polymer test -s 'default'; - fi + - xvfb-run polymer test --module-resolution=node --npm + - 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then polymer test --module-resolution=node --npm -s ''default''; fi' dist: trusty + diff --git a/bower.json b/bower.json deleted file mode 100644 index e397a22..0000000 --- a/bower.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "iron-form", - "version": "2.3.0", - "description": "Wrapper around native form that submits native and custom elements", - "keywords": [ - "web-components", - "polymer", - "form" - ], - "authors": [ - "The Polymer Authors" - ], - "main": "iron-form.html", - "private": true, - "repository": { - "type": "git", - "url": "git://github.com/PolymerElements/iron-form.git" - }, - "license": "http://polymer.github.io/LICENSE.txt", - "homepage": "https://github.com/PolymerElements/iron-form", - "ignore": [], - "dependencies": { - "polymer": "Polymer/polymer#1.9 - 2", - "iron-ajax": "PolymerElements/iron-ajax#1 - 2" - }, - "devDependencies": { - "iron-component-page": "PolymerElements/iron-component-page#1 - 2", - "iron-demo-helpers": "PolymerElements/iron-demo-helpers#1 - 2", - "paper-button": "PolymerElements/paper-button#1 - 2", - "paper-checkbox": "PolymerElements/paper-checkbox#1 - 2", - "paper-dropdown-menu": "PolymerElements/paper-dropdown-menu#1 - 2", - "paper-input": "PolymerElements/paper-input#1 - 2", - "paper-item": "PolymerElements/paper-item#1 - 2", - "paper-listbox": "PolymerElements/paper-listbox#1 - 2", - "paper-spinner": "PolymerElements/paper-spinner#1 - 2", - "paper-styles": "PolymerElements/paper-styles#1 - 2", - "web-animations-js": "web-animations/web-animations-js#^2.2", - "web-component-tester": "Polymer/web-component-tester#^6.0.0", - "webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0" - }, - "variants": { - "1.x": { - "dependencies": { - "polymer": "Polymer/polymer#^1.9", - "iron-ajax": "PolymerElements/iron-ajax#^1.0.0" - }, - "devDependencies": { - "iron-component-page": "PolymerElements/iron-component-page#^1.0.0", - "iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0", - "paper-button": "PolymerElements/paper-button#^1.0.0", - "paper-checkbox": "PolymerElements/paper-checkbox#^1.0.0", - "paper-dropdown-menu": "PolymerElements/paper-dropdown-menu#^1.0.0", - "paper-input": "PolymerElements/paper-input#^1.0.0", - "paper-item": "PolymerElements/paper-item#^1.0.0", - "paper-menu": "PolymerElements/paper-menu#^1.0.0", - "paper-spinner": "PolymerElements/paper-spinner#^1.0.0", - "paper-styles": "PolymerElements/paper-styles#^1.0.0", - "test-fixture": "PolymerElements/test-fixture#^1.0.0", - "web-animations-js": "web-animations/web-animations-js#^2.2", - "web-component-tester": "Polymer/web-component-tester#^4.0.0", - "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" - }, - "resolutions": { - "webcomponentsjs": "^0.7" - } - } - }, - "resolutions": { - "webcomponentsjs": "^1.0.0" - } -} diff --git a/demo/cats-only.html b/demo/cats-only.js similarity index 50% rename from demo/cats-only.html rename to demo/cats-only.js index 16b48a6..82562ff 100644 --- a/demo/cats-only.html +++ b/demo/cats-only.js @@ -1,4 +1,4 @@ - - - - - - - - - + // Overidden from Polymer.IronValidatableBehavior. Will set the `invalid` + // attribute automatically, which should be used for styling. + _getValidity: function() { + return this.value === 'cats'; + } +}); diff --git a/demo/index.html b/demo/index.html index 226da7b..5190643 100644 --- a/demo/index.html +++ b/demo/index.html @@ -16,23 +16,34 @@ - + - - - - - - - - - - - - + + + + + + + + + + + + - + + -
+ + </script> @@ -118,7 +135,7 @@

You can submit a form in many different ways: by manually calling subm
- You must check this box. + You must check this box.

Using a native button to submit the form will display the native browser validation UI for native elements:

@@ -126,8 +143,8 @@

You can submit a form in many different ways: by manually calling subm

Using a custom element to submit the form will not display the native browser validation UI:

- Submit - Reset + Submit + Reset
@@ -136,7 +153,7 @@

You can submit a form in many different ways: by manually calling subm form2.addEventListener('iron-form-submit', function(event) { this.querySelector('.output').innerHTML = JSON.stringify(event.detail); }); - + </script> @@ -145,9 +162,9 @@

To customize the request sent to the server, you can listen to the iro @@ -170,12 +187,12 @@

Example of an iron-form reacting to state changes

+ + + +

Iron-form respects the novalidate form attribute

+ + @@ -219,11 +294,23 @@

Iron-form respects the novalidate form attribute

- + @@ -245,11 +332,23 @@

iron-form respects nested elements

- +

diff --git a/index.html b/index.html index acd7140..4a4ce47 100644 --- a/index.html +++ b/index.html @@ -16,10 +16,10 @@ iron-form - + - - + + diff --git a/iron-form.d.ts b/iron-form.d.ts deleted file mode 100644 index c284ab5..0000000 --- a/iron-form.d.ts +++ /dev/null @@ -1,151 +0,0 @@ -/** - * DO NOT EDIT - * - * This file was automatically generated by - * https://github.com/Polymer/gen-typescript-declarations - * - * To modify these typings, edit the source file(s): - * iron-form.html - */ - -/// -/// - -/** - * `` is a wrapper around the HTML `
` element, that can - * validate and submit both custom and native HTML elements. Note that this - * is a breaking change from iron-form 1.0, which was a type extension. - * - * It has two modes: if `allow-redirect` is true, then after the form submission you - * will be redirected to the server response. Otherwise, if it is false, it will - * use an `iron-ajax` element to submit the form contents to the server. - * - * Example: - * - * - * - * - * I like donuts
- * - * - *
- * - * By default, a native ` - * - * function submitForm() { - * document.getElementById('myForm').submit(); - * } - * - * If you are not using the `allow-redirect` mode, then you also have the option of - * customizing the request sent to the server. To do so, you can listen to the `iron-form-presubmit` - * event, and modify the form's [`iron-ajax`](https://elements.polymer-project.org/elements/iron-ajax) - * object. However, If you want to not use `iron-ajax` at all, you can cancel the - * event and do your own custom submission: - * - * Example of modifying the request, but still using the build-in form submission: - * - * form.addEventListener('iron-form-presubmit', function() { - * this.request.method = 'put'; - * this.request.params['extraParam'] = 'someValue'; - * }); - * - * Example of bypassing the build-in form submission: - * - * form.addEventListener('iron-form-presubmit', function(event) { - * event.preventDefault(); - * var firebase = new Firebase(form.getAttribute('action')); - * firebase.set(form.serializeForm()); - * }); - * - * Note that if you're dynamically creating this element, it's mandatory that you - * first create the contained `
` element and all its children, and only then - * attach it to the ``: - * - * var wrapper = document.createElement('iron-form'); - * var form = document.createElement('form'); - * var input = document.createElement('input'); - * form.appendChild(input); - * document.body.appendChild(wrapper); - * wrapper.appendChild(form); - */ -interface IronFormElement extends Polymer.Element { - - /** - * Set this to true if you don't want the form to be submitted through an - * ajax request, and you want the page to redirect to the action URL - * after the form has been submitted. - */ - allowRedirect: boolean|null|undefined; - - /** - * HTTP request headers to send. See PolymerElements/iron-ajax for - * more details. Only works when `allowRedirect` is false. - */ - headers: object|null|undefined; - - /** - * Set the `withCredentials` flag on the request. See - * PolymerElements/iron-ajax for more details. Only works when - * `allowRedirect` is false. - */ - withCredentials: boolean|null|undefined; - attached(): void; - detached(): void; - _init(): void; - _saveInitialValues(): void; - - /** - * Validates all the required elements (custom and native) in the form. - * - * @returns True if all the elements are valid. - */ - validate(): boolean; - - /** - * Submits the form. - */ - submit(event?: Event|null): void; - - /** - * Resets the form to the default values. - */ - reset(event?: Event|null): void; - - /** - * Serializes the form as will be used in submission. Note that `serialize` - * is a Polymer reserved keyword, so calling `someIronForm`.serialize()` - * will give you unexpected results. - * - * @returns An object containing name-value pairs for elements that - * would be submitted. - */ - serializeForm(): {[key: string]: any}; - _handleFormResponse(event: any): void; - _handleFormError(event: any): void; - _makeAjaxRequest(json: any): void; - _getValidatableElements(): any; - _getSubmittableElements(): any; - _serializeElementValues(element: any): any; - _serializeSelectValues(element: any): any; - _serializeInputValues(element: any): any; - _createHiddenElement(name: any, value: any): any; - _addSerializedElement(json: any, name: any, value: any): void; -} - -interface HTMLElementTagNameMap { - "iron-form": IronFormElement; -} diff --git a/iron-form.html b/iron-form.html deleted file mode 100644 index c59edbf..0000000 --- a/iron-form.html +++ /dev/null @@ -1,618 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/iron-form.js b/iron-form.js new file mode 100644 index 0000000..a952212 --- /dev/null +++ b/iron-form.js @@ -0,0 +1,619 @@ +/** +@license +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +Code distributed by Google as part of the polymer project is also +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +*/ +/** +`` is a wrapper around the HTML `` element, that can +validate and submit both custom and native HTML elements. Note that this +is a breaking change from iron-form 1.0, which was a type extension. + +It has two modes: if `allow-redirect` is true, then after the form submission you +will be redirected to the server response. Otherwise, if it is false, it will +use an `iron-ajax` element to submit the form contents to the server. + + Example: + + + + + I like donuts
+ + +
+ +By default, a native ` + + function submitForm() { + document.getElementById('myForm').submit(); + } + +If you are not using the `allow-redirect` mode, then you also have the option of +customizing the request sent to the server. To do so, you can listen to the `iron-form-presubmit` +event, and modify the form's [`iron-ajax`](https://elements.polymer-project.org/elements/iron-ajax) +object. However, If you want to not use `iron-ajax` at all, you can cancel the +event and do your own custom submission: + + Example of modifying the request, but still using the build-in form submission: + + form.addEventListener('iron-form-presubmit', function() { + this.request.method = 'put'; + this.request.params['extraParam'] = 'someValue'; + }); + + Example of bypassing the build-in form submission: + + form.addEventListener('iron-form-presubmit', function(event) { + event.preventDefault(); + var firebase = new Firebase(form.getAttribute('action')); + firebase.set(form.serializeForm()); + }); + +Note that if you're dynamically creating this element, it's mandatory that you +first create the contained `
` element and all its children, and only then +attach it to the ``: + + var wrapper = document.createElement('iron-form'); + var form = document.createElement('form'); + var input = document.createElement('input'); + form.appendChild(input); + document.body.appendChild(wrapper); + wrapper.appendChild(form); + +@element iron-form +@hero hero.svg +@demo demo/index.html +*/ +/* + FIXME(polymer-modulizer): the above comments were extracted + from HTML and may be out of place here. Review them and + then delete this comment! +*/ +import '@polymer/polymer/polymer-legacy.js'; + +import '@polymer/iron-ajax/iron-ajax.js'; +import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js'; +import { html } from '@polymer/polymer/lib/utils/html-tag.js'; +import { dom } from '@polymer/polymer/lib/legacy/polymer.dom.js'; + +Polymer({ + _template: html` + + + + + + + +`, + + is: 'iron-form', + + properties: { + /* + * Set this to true if you don't want the form to be submitted through an + * ajax request, and you want the page to redirect to the action URL + * after the form has been submitted. + */ + allowRedirect: {type: Boolean, value: false}, + /** + * HTTP request headers to send. See PolymerElements/iron-ajax for + * more details. Only works when `allowRedirect` is false. + */ + headers: { + type: Object, + value: function() { + return {}; + } + }, + /** + * Set the `withCredentials` flag on the request. See + * PolymerElements/iron-ajax for more details. Only works when + * `allowRedirect` is false. + */ + withCredentials: {type: Boolean, value: false}, + }, + + /** + * 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 + */ + + /** + * Fired before the form is submitted. + * + * @event iron-form-presubmit + */ + + /** + * Fired after the form is reset. + * + * @event iron-form-reset + */ + + /** + * Fired after the form is submitted and a response is received. An + * IronRequestElement is included as the event.detail object. + * + * @event iron-form-response + */ + + /** + * Fired after the form is submitted and an error is received. An + * error message is included in event.detail.error and an + * IronRequestElement is included in event.detail.request. + * + * @event iron-form-error + */ + + /** + * @return {void} + */ + attached: function() { + // We might have been detached then re-attached. + // Avoid searching again for the
if we already found it. + if (this._form) { + return; + } + // Search for the ``, if we don't find it, observe for + // mutations. + this._form = dom(this).querySelector('form'); + if (this._form) { + this._init(); + // Since some elements might not be upgraded yet at this time, + // we won't be able to look into their shadowRoots for submittables. + // We wait a tick and check again for any missing submittable default + // values. + this.async(this._saveInitialValues.bind(this), 1); + } else { + this._nodeObserver = dom(this).observeNodes(function(mutations) { + for (var i = 0; i < mutations.addedNodes.length; i++) { + if (mutations.addedNodes[i].tagName === 'FORM') { + this._form = mutations.addedNodes[i]; + // At this point in time, all custom elements are expected + // to be upgraded, hence we'll be able to traverse their + // shadowRoots. + this._init(); + dom(this).unobserveNodes(this._nodeObserver); + this._nodeObserver = null; + } + } + }.bind(this)); + } + }, + + /** + * @return {void} + */ + detached: function() { + if (this._nodeObserver) { + dom(this).unobserveNodes(this._nodeObserver); + this._nodeObserver = null; + } + }, + + _init: function() { + this._form.addEventListener('submit', this.submit.bind(this)); + this._form.addEventListener('reset', this.reset.bind(this)); + + // Save the initial values. + this._defaults = this._defaults || new WeakMap(); + this._saveInitialValues(); + }, + + _saveInitialValues: function() { + var nodes = this._getValidatableElements(); + for (var i = 0; i < nodes.length; i++) { + var node = nodes[i]; + if (!this._defaults.has(node)) { + // Submittables are expected to have `value` property, + // that's what gets serialized. + var defaults = {value: node.value}; + if ('checked' in node) { + defaults.checked = node.checked; + } + // In 1.x iron-form would reset `invalid`, so + // keep it here for backwards compat. + if ('invalid' in node) { + defaults.invalid = node.invalid; + } + this._defaults.set(node, defaults); + } + } + }, + + /** + * Validates all the required elements (custom and native) in the form. + * @return {boolean} True if all the elements are valid. + */ + validate: function() { + // If you've called this before distribution happened, bail out. + if (!this._form) { + return false; + } + + if (this._form.getAttribute('novalidate') === '') + return true; + + // Start by making the form check the native elements it knows about. + var valid = this._form.checkValidity(); + var elements = this._getValidatableElements(); + + // Go through all the elements, and validate the custom ones. + for (var el, i = 0; el = elements[i], i < elements.length; i++) { + // This is weird to appease the compiler. We assume the custom element + // has a validate() method, otherwise we can't check it. + var validatable = /** @type {{validate: (function() : boolean)}} */ (el); + if (validatable.validate) { + valid = !!validatable.validate() && valid; + } + } + return valid; + }, + + /** + * Submits the form. + * + * @param {Event=} event + * @return {void} + */ + submit: function(event) { + // We are not using this form for submission, so always cancel its event. + if (event) { + event.preventDefault(); + } + + // If you've called this before distribution happened, bail out. + if (!this._form) { + return; + } + + if (!this.validate()) { + this.fire('iron-form-invalid'); + return; + } + + // Remove any existing children in the submission form (from a previous + // submit). + this.$.helper.textContent = ''; + + var json = this.serializeForm(); + + // If we want a redirect, submit the form natively. + if (this.allowRedirect) { + // If we're submitting the form natively, then create a hidden element for + // each of the values. + for (var element in json) { + this.$.helper.appendChild( + this._createHiddenElement(element, json[element])); + } + + // Copy the original form attributes. + this.$.helper.action = this._form.getAttribute('action'); + this.$.helper.method = this._form.getAttribute('method') || 'GET'; + this.$.helper.contentType = this._form.getAttribute('enctype') || + 'application/x-www-form-urlencoded'; + + this.$.helper.submit(); + this.fire('iron-form-submit'); + } else { + this._makeAjaxRequest(json); + } + }, + + /** + * Resets the form to the default values. + * + * @param {Event=} event + * @return {void} + */ + reset: function(event) { + // We are not using this form for submission, so always cancel its event. + if (event) + event.preventDefault(); + + // If you've called this before distribution happened, bail out. + if (!this._form) { + return; + } + + // Ensure the native form fired the `reset` event. + // User might have bound `