Name:
Email:
Input Errors
Icons
Template
<div class="layout layout-sm-column">
<PaperInput @class="flex-30" @label="Name" @placeholder="Enter name" @value= @onChange= />
<PaperInput @class="flex-30" @label="E-mail" @type="email" @value= @onChange= />
<PaperInput @class="flex-40" @label="Password" @type="password" @value= @onChange= />
</div>
<div class="layout layout-sm-column">
<PaperInput @class="flex" @label="Submission date" @type="date" @value= @onChange= />
<PaperInput @class="flex" @label="Company (disabled)" @type="text" @value="Google" @disabled= @onChange= />
</div>
<PaperInput @textarea= @block= @label="Biography" @maxlength= @passThru= @value= @onChange= />
<p>Name: </p>
<p>Email: </p>
<h3>Input Errors</h3>
<p>
<PaperInput @label="Address" @value= @onChange= @required= @errorMessages= />
<PaperInput @type="number" @label="Maximum Value" @value= @onChange= @max="5" @errorMessages= />
<PaperInput @type="number" @label="Minimum Value" @value= @onChange= @min="1" @errorMessages= />
<PaperInput @label="Maximum Character Length" @value= @onChange= @required= @maxlength= @errorMessages= />
<PaperInput @label="All Constraints" @value= @onChange= @required= @min="2" @max="10" @maxlength="2" @errorMessages= />
<PaperInput @label="Required asterisk only" @value= @onChange= @required="style" />
</p>
<h3>Icons</h3>
<p>
<PaperInput @label="Name" @value= @onChange= @icon="person" />
<PaperInput @placeholder="Phone Number" @type="text" @value= @onChange= @icon="phone" />
<PaperInput @label="Email (no messages)" @type="email" @value= @onChange= @icon="email" @required= @hideAllMessages= />
<PaperInput @placeholder="Address" @type="text" @value= @onChange= @icon="place" />
<PaperInput @label="Name on right" @type="text" @value= @onChange= @iconRight="person" />
</p>
About Required.
Note that required, when set to true
both causes the input element to be validated to contain a value and causes the label to be styled
with a required asterisk (*). If only the asterisk styling is desired, such as when using external
validation mesages, use required="style". To set the
html5 required attributed on the input element itself, use the passThru
option, setting required="required" as described below.
Input Attributes
These additional attributes will be passed through to the input helper inside of paper-input. See the Ember Input Helpers for more information. This is an example of using one of the attributes.
<PaperInput @value= @onChange= @label="Number of bagels" @type="number" @passThru= />
Available Attributes for Text Fields
accept,
autocomplete,
autosave,
form,
formaction,
formenctype,
formmethod,
formnovalidate,
formtarget,
inputmode,
maxlength,
min,
max,
multiple,
name,
pattern,
required,
selectionDirection,
size,
spellcheck,
step,
tabindex, and
width.
Available Attributes for Text Areas
cols,
form,
maxlength,
name,
readonly,
required,
rows,
selectionDirection,
selectionEnd,
selectionStart,
spellcheck,
tabindex, and
wrap.
Actions
You may also pass through an action closures to receive notification upon
onFocus, onBlur,
onKeyDown and onChange.
<PaperInput @label="Event demonstration" @value= @onChange= @onFocus= @onBlur= @onKeyDown= />
Input Text Helpers
You can pass in a helper text to the paper-input's block. Some useful properties are yieled to the block to help you conditionally render the text.
<PaperInput @value= @onChange= @label="Email" @type="email" as |input|>
<div class="hint">How can we reach you?</div>
</PaperInput>
| Option | Type | Description |
|---|---|---|
charCount |
integer | Length of the current input's value. |
hasValue |
boolean | true if the input is filled. |
isInvalid |
boolean | true if input is in error. |
isInvalidAndTouched |
boolean | true if input is in error and the user interacted with it. |
isTouched |
boolean | true is the user interacted with it. |
validationErrorMessages |
array | List of input's errors. |
Custom Validations
In addition to required,
min, max,
and maxlength, you may define your own
custom validations. Custom validations are defined by an object with two
attributes, message and
validate. You may bind a single validation
object, or an array of validation objects.
| Option | Type | Description |
|---|---|---|
message |
string | The text you want to display to the user when there is an error. |
validate |
function | A validator that returns a falsy value when the validation message should be displayed. The function receives one argument: the input's value. |
Here is an example of validating the input value matches typical email formats.
Template
<PaperInput @label="E-mail" @type="email" @value= @onChange= @customValidations= />
Define your emailValidation object in your controller.
emailValidation = [
{
message: 'Please provide email in a valid format',
validate: (inputValue) => {
let emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return emailPattern.test(inputValue);
},
},
];
You may also define multiple custom constraints by using an array of validation objects.
<PaperInput @class="md-block" @label="Value should be even and equal 4." @type="email" @value= @onChange= @customValidations= />
multipleConstraints = [
{
message: 'Value is not even',
validate: (inputValue) => +inputValue % 2 === 0,
},
{
message: 'Value does not equal 4',
validate: (inputValue) => +inputValue === 4,
},
];
Setting validation messages from external validations
While {{paper-input}} supplies four
built-in validation rules and the ability to specify programmed custom
validations, some projects need more complicated and elaborate validations,
such as are provided by ember-cp-validations or another validation add-on.
In this case, the code to validate the user input is outside of
paper-input, and only the resulting messages need be provided to the
{{paper-input}} helper.
Template
<PaperCard as |card|>
<card.content>
<div class="layout layout-sm-row">
<PaperInput @class="flex-50" @label="User name" @value= @onChange= @errors= />
</div>
<div class="layout layout-sm-row">
<PaperInput @label="Password" @class="flex-34" @type="password" @value= @onChange= @errors= />
<PaperInput @label="E-mail" @class="flex-33" @type="email" @value= @onChange= @errors= />
<PaperInput @label="Retype your e-mail" @class="flex-33" @type="email" @value= @onChange= @errors= />
</div>
</card.content>
</PaperCard>
The errors argument can either be an array of messages or an array of
hashes, each with a message property and an optional attr property,
which indentifies the type of error for possible theming or other use.
The latter format is compatible with errors from ember-data.