ember-paper provides a paper-form to help you build forms
and keep track of the form's global validity state. This component uses
the html form tag by default, so expected form behavior will occur.
(For example, pressing the enter key from within one of the form's
inputs will submit the form.)
paper-form yields paper-input,
paper-select
and paper-autocomplete controls.
In the following example you can see how we use the yielded form controls:
Template
<PaperForm @onSubmit= as |form|>
<div class="layout-row">
<div class="layout-column flex-50">
<form.input @label="First Name" @value= @onChange= @required= />
<form.input @label="Last Name" @value= @onChange= />
</div>
<div class="layout-column flex-50">
<form.autocomplete @required= @options= @selected= @searchField="name" @labelPath="name" @label="Country" @noMatchesMessage="Oops this country doesn't exist." @onSelectionChange= as |country select|>
<PaperAutocompleteHighlight @label= @searchText= @flags="i" />
</form.autocomplete>
<form.input @type="number" @label="Age" @value= @onChange= @min= @max= @required= />
</div>
</div>
<div class="layout-row">
<form.submit-button @raised= @primary=>Submit</form.submit-button>
</div>
</PaperForm>
A typical use case for the global validity state is to toggle the submit button
between a disabled and enabled state. Here is how you would do that with
paper-form:
Template
<PaperForm @onSubmit= as |form|>
<div class="layout-row">
<form.input @label="Favorite Letter" @value= @onChange= @required= @maxlength= />
</div>
<div class="layout-row">
<form.submit-button @raised= @primary= @disabled=>
Submit
</form.submit-button>
</div>
</PaperForm>
If you prefer, you can trigger the submit action without using a submit button.
paper-form also yields an onSubmit action you
can use wherever you like, e.g:
<button {{on "click" form.onSubmit}}>
Submit
</button>
You can also extend paper-input to make your own custom components (money inputs, phone inputs, etc.) and the form validation will still work out of the box! Just replace paper-input with your component's name.
Template
<PaperForm @onSubmit= as |form|>
<div class="layout-row">
<PaperInput @label="Favorite Number" @value= @onChange= @required= @min= @max= />
</div>
<div class="layout-row">
<form.submit-button @raised= @primary=>Submit</form.submit-button>
</div>
</PaperForm>