Hint text goes here
200 Character limit here
200 Character limit here
Input fields let users share information required in order to complete a task.
Hint text goes here
200 Character limit here
200 Character limit here
<matInput>
is a directive that allows native <input>
and <textarea>
elements to work with <mat-form-field>
.
Note that this component may require additional styling.
To create an Input Field, use Textbox and/or Text area elements from the toolbox on the right.
The styles for these elements should be automatically applied along with the styles for their error states.
The Mendix toolkit can be found here.
Use the codes below to add this component to your project. Download the latest version of the library to easily implement our full range of components.
Execute the following command to install this component.
Import the following into your app.module.ts file.
<cpc-ds-input-field labelText = "Full name" fieldValue = "This is text" [formControl]="fullNameFormControl" id = 'fullName'> </cpc-ds-input-field>
<cpc-ds-input-field labelText = "Full name" fieldValue = "This is text" [formControl]="disableFullNameFormControl" id = 'fullName'> </cpc-ds-input-field>
<cpc-ds-input-field labelText = "Full name" fieldValue = "This is text" [readOnlyField] = "true" [formControl]="fullNameReadOnlyFormControl" id = 'fullName'> </cpc-ds-input-field>
<cpc-ds-input-field labelText = "Full name" hintText = "Don't disclose personal infos" fieldValue = "This is text" [readOnlyField] = "false" (click)="beep()" [formControl]="fullNameFormControl" id = 'fullName'> </cpc-ds-input-field>
<cpc-ds-input-field labelText = "Password" type="password" id = 'password'> </cpc-ds-input-field>
<cpc-ds-input-field id = 'additionalDetails' inputFormat = "textAreaType" [formControl]="textareaFormControl" labelText = "Additional Information" [showMaxLengthLabel] = "true" [maxchar] = "140"> </cpc-ds-input-field>
Name | Type | Default | Description |
---|---|---|---|
id | string | id |
id for the input field |
inputFormat | string |
There are two formats available:
Library will show a text field by default. If you want textarea, use inputFormat “textAreaType” |
|
name | string | txt |
The name of the input field |
type | string | text |
There are 2 types available:
|
labelText | string |
Text for the label |
|
hintText | string |
Hint text for the field |
|
readOnlyField | boolean | false |
Make field read-only |
showMaxLengthLabel | boolean | false |
Show the maximum length available in textarea |
maxchar | number | 120 |
The number of characters allowed in textarea |
formControl | Form control |
FormControl for the input field fullNameFormControl = new FormControl({ value: 'TEST', disabled: false }, [Validators.required]); |
|
(click) | event |
Call your method click event
|
Import the following into your theme or page.
<script src="[JS-PLACE-HOLDER]"></script>
<label for="fullname">Full name</label> <input id="fullname" type="text" autocomplete="off">
<label for="error">Full name *</label> <input aria-required="true" aria-invalid="true" aria-describedby="errMsg2" id="error" type="text" class="error" autocomplete="off"> <div id="errMsg2" class="ds-error">Error message goes here</div>
<label id="fullnameHint">Full name</label> <p id="hintText" class="hintText">Hint text goes here</p> <input type="text" autocomplete="off" aria-labelledby="fullnameHint hintText">
<!-- Read Only --> <label for="fullnameReadonly">Full name</label> <input id="fullnameReadonly" readonly value="Read only text here" type="text" autocomplete="off">
<label for="disabled">Full name</label> <input aria-disabled="true" disabled id="disabled" class="disabled" type="text" autocomplete="off">
<label for="textarea" id="textarea-label"> Additional Information </label> <textarea id="textarea" maxLength="102" aria-labelledby="textarea-label textarea-maxCharacter"> </textarea> <p id="textarea-maxCharacter" class="maxCharacter"> 102 Character limit here </p>
<label for="textarea2" id="textarea2-label"> Additional Information </label> <textarea aria-invalid="true" aria-describedby="errMsg" aria-labelledby="textarea2-label textarea2-maxCharacter" id="textarea2" class="error" maxLength="10"> </textarea> <p aria-live="polite" id="textarea2-maxCharacter" class="maxCharacter"> 10 Character limit here </p> <div id="errMsg" class="ds-error"> Error message goes here </div>
Input fields enable users to submit unique or complex data.
Short input fields are useful for names, addresses or any other piece of information that is unique from user to user.
Long input fields (known as text areas) are ideal for collecting qualitative responses or complex data.
When a user is typing in a password, it should be hidden, unless a user chooses to reveal it.
Consider the amount and type of information being asked for when determining the length of the field. Align labels to the top and left of the input field to let users scan quickly.
Input fields are large components and will generally take up most of a form. This is an important consideration when structuring forms.
Helper text is a powerful way to influence input field responses, but not always helpful. Consider the value of the helper text you include in your design. If you can’t make a confident case for including some, remove it!
Input fields have default, focus, active and error states.
Error messages go beneath the input field.
On form validation, error messages are shown when user has provided incorrect information or violated at least 1 requirement. Provide context so the user can correct their errors.
If a user must input information according to a specific format, make sure to indicate that clearly. Don’t rely exclusively on placeholder text as it disappears quickly and is not always read by assistive technologies. Instead, explain formatting requirements using hint text below the field.
Many input fields support a variety of input formats, automatically translating data into a formal structure upon submission. For example, when inputting a postal code, users can use any combination of uppercase, lowercase, space, no-space and hyphenated inputs. This data is validated after submission, ‘translated’ to the proper format, and then captured by your form. In cases like these, there is no need to indicate a requirement for specific formatting.
Use labels to ensure input fields are announced when brought into focus.
Assistive technologies do not treat placeholder text as labels. Some are not supported and not displayed in older web browsers. It may even make users think that the form input is already filled out.
Use hint text over placeholder text whenever possible. Provide the information that the user needs to fill out the form.
Write input field labels in plain language. Inform the users what they should be typing into the fields.
Guidelines | Examples | |
---|---|---|
Recommended length | 1 to 3 words for labels | Date |
Line wrap | Avoid | Name |
Phrasing | A noun, or a group of words that act as one | Promo code |
Case | Sentence case | Additional pickup instructions |
For forms that consist of five or more different input fields that are a mix of required and optional fields, it’s helpful to add the following statement.
“All fields are required, unless indicated as optional.”
For fields that are optional, add the word “(optional)” in parentheses next to the input field label.
Use examples to complement input field labels when further clarity would be helpful. The additional microcopy can demonstrate how to format field entries and can help users quickly visualize what they need to type. Giving users examples can improve efficiency and help them avoid errors.
Write error messages that focus on directions and how users can quickly fix the problem to move forward. Error messages should be used to educate users, rather than only deliver negative feedback. The tone of error messages should be polite and constructive. You can offer an alternate solution through a link, if it’s possible that the user needs something else. Avoid error message codes, use plain language and minimize the text.
Use accessible error messages that are visible to assistive technology and link users to the corresponding entries. If multiple errors apply, add an overview accessibility error message that links users to the applicable errors.
When the input field has focus:
Autocomplete attributes help users with limited dexterity and cognitive disabilities. A complete list of HTML 5.2 autofill input type purposes is available courtesy of W3C.
Screen reader users need to be notified of a text area’s character limit. This is best achieved by including:
The following WAI-ARIA roles and properties can be associated with input fields and text area elements:
When testing an input field, the tester must ensure: