Appearance style for the field.
Wether outline
(default), legacy
, fill
or standard
.
Whether the control is disabled.
Error text to be shown underneath the form field control.
Input will be focused on appearance if set to true
.
Hint text to be shown underneath the form field control.
The floating label for a field.
Input mask options.
If mask will allow the use of negative numbers.
Should value be emitted with charaters added by mask.
Expression that constrains user input.
If it exists, autocomplete suggestions will not work.
You can check available mask
options here - https://jsdaddy.github.io/ngx-mask-page.
If the leadZeroDateTime
parameter is true
, skipped symbols of date or time will be replaced by 0.
Prefix for the input.
If mask is shown while typing, or not.
Suffix for the input.
If mask is separator
, defines which character will separate thousands.
Executed with current value when ENTER key is pressed or an option from suggestions is selected.
Executed when autocomplete field is focused.
Executed with an input value from user.
The placeholder text.
Autocomplete suggestions.
Specify the width of the autocomplete panel. Can be any CSS sizing value, otherwise it will match the width of its host.
Wether value of the field should be emitted when user is blurred out of the control.
Value of the input.
<drayman-text-field />
Text field powered by Angular Material and ngx-mask libraries.
Example of usage
Simple text field
export const component: DraymanComponent = async ({ forceUpdate }) => { let name = ''; let typing = false; return () => { // User started typing const onValueChangeStart = async () => { typing = true; await forceUpdate(); } // User stopped typing with some `value` const onValueChange = async ({ value }) => { typing = false; name = value; await forceUpdate(); } return <div> <drayman-text-field label="Name" value={name} onValueChangeStart={onValueChangeStart} onValueChange={onValueChange} /> <div> {name && <p>Hello, {name}!</p>} <p>{typing ? `You are typing!` : `You aren't typing!`}</p> </div> </div> }; }
Text field with autocomplete and remote result caching.
import axios from 'axios'; import _ from 'lodash'; const getCountriesFromCache = _.memoize(async (value) => { const result = await axios.get(`https://api.first.org/data/v1/countries?q=${value}&limit=10`); return Object.values(result.data.data).map((x: any) => ({ value: x.country, label: x.country })); }); export const component: DraymanComponent = async ({ forceUpdate }) => { let countries: { value: string; label: string; }[] = []; let searchValue = ''; const getCountries = async () => { countries = await getCountriesFromCache(searchValue); await forceUpdate(); } return () => { return ( <drayman-text-field label="Country" value={searchValue} suggestions={countries} onFocus={ async () => { if (!countries.length) { await getCountries(); } } } onValueChange={ async ({ value }) => { searchValue = value; await getCountries(); } } /> ); } }