https://github.com/polymerelements/iron-form
Custom form element
https://github.com/polymerelements/iron-form
Last synced: 11 months ago
JSON representation
Custom form element
- Host: GitHub
- URL: https://github.com/polymerelements/iron-form
- Owner: PolymerElements
- Archived: true
- Created: 2015-05-13T01:01:02.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-10-16T14:02:54.000Z (over 2 years ago)
- Last Synced: 2024-12-25T00:05:37.260Z (over 1 year ago)
- Language: HTML
- Homepage: https://www.webcomponents.org/element/PolymerElements/iron-form
- Size: 588 KB
- Stars: 63
- Watchers: 21
- Forks: 81
- Open Issues: 46
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/@polymer/iron-form)
[](https://travis-ci.org/PolymerElements/iron-form)
[](https://webcomponents.org/element/@polymer/iron-form)
## <iron-form>
`` is a wrapper around the HTML `` element, that can
validate and submit both custom and native HTML elements.
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.
See: [Documentation](https://www.webcomponents.org/element/@polymer/iron-form),
[Demo](https://www.webcomponents.org/element/@polymer/iron-form/demo/demo/index.html).
## Usage
### Installation
```
npm install --save @polymer/iron-form
```
### In an html file
```html
import '@polymer/iron-form/iron-form.js';
import '@polymer/paper-checkbox/paper-checkbox.js';
I like donuts
```
By default, a native `` element (or `input type="submit"`) will submit this form.
However, if you want to submit it from a custom element's click handler, you need to explicitly
call the `iron-form`'s `submit` method:
```html
Submit
function submitForm() {
document.getElementById('iron-form').submit();
}
```
### In a Polymer 3 element
```js
import {PolymerElement, html} from '@polymer/polymer';
import '@polymer/iron-form/iron-form.js';
import '@polymer/paper-checkbox/paper-checkbox.js';
class SampleElement extends PolymerElement {
static get template() {
return html`
I like donuts
`;
}
}
customElements.define('sample-element', SampleElement);
```
## Contributing
If you want to send a PR to this element, here are
the instructions for running the tests and demo locally:
### Installation
```sh
git clone https://github.com/PolymerElements/iron-form
cd iron-form
npm install
npm install -g polymer-cli
```
### Running the demo locally
```sh
polymer serve --npm
open http://127.0.0.1:/demo/
```
### Running the tests
```sh
polymer test --npm
```