Skip to main content

Field Component

Field Props#

NameTypeDefaultDescription
afterChangefunctionundefinedMiddleware that will be called with the field new value and its name as a second argument after each change: afterChange(newValue). Ex: afterChange={(newValue, fieldName) => console.log(newValue)}
autoCapitalizeOnbooleanfalseEnables autocapitalize
autoCompleteOffbooleanfalseDisables autocomplete for this input
autoCorrectOnbooleanfalseEnables autocorrect
disabledbooleanundefinedProgrammatically disable a field. Ex: disabled={someCondition === true}
fieldstringundefinedThe field that should be controlled by frmx. You can target nested fields like so "a.nested.field" (lodash notation).
getValueFromArgsfunction(args) => args[0].target.valuePass a custom function to get back the value from the onChange args. Useful for instance when interacting with material ui components as they often pass the newValue through the second argument. Example: <Field ... getValueFromArgs={args => args[1]}>...</Field>
idstringundefinedThe id you wish to give to the underlying component.
isErrorPropstringundefinedThe name of the prop used by the underlying component to trigger an error state based on a boolean.
namestringundefinedThe name you wish to give to the underlying component.
onChangePropstring"onChange"The name of the prop used to update the component with its value.
trimbooleanfalsePass this prop if you want the input to be trimmed (if it's a string). The user won't be able to type whitespaces at the beginning or the end of the input field.
typestring"text"The type of your input. Note: Pass "checkbox" for checkboxes AND switches.
valuePropstring"value"The name of the component that holds the field's value.
...restanyundefinedAny other props will be spread on to the <form> / <div> tag

Example Usage#

<FieldautoCapitalizeOffautoCorrectOffautoComplete='email'path="a.nested.field"getValueFromArgsid='im-a-teapot'isErrorPropname='important-field'onChangePropvalueProprequiredtype="text"trim/>

Notes#

Pathname notation#

Use only "." notation, even for array elements, otherwise you might run into bugs. For instance, to access the string "baz" in {a: ["bar", {b: "baz"}]}}, you would give the field "a.0.b".

Child(ren)#

<Field/> can have only one child element.