created:7/7/2021
updated:7/7/2021
loc
229
comments
4%
passed
4
failed
6
coverage
10%
grommet-controls
3.0.2A Form with built-in validation.
- config
- source
() => (<FormonSubmit={() => console.log('onSubmit')}pad={{horizontal: 'small',}}><PasswordInputFieldlabel="Password"name="password"validation={[validators.required(),validators.minLength(8),validators.alphaNumeric(),]}/><PasswordInputFieldlabel="Confirm Password"name="password1"validation={[validators.equalsField('password', 'the above password')]}/><TextInputFieldlabel="URL"name="url"validation={[validators.required(), validators.url()]}/><SelectFieldname="gender"options={['male', 'female']}validation={[validators.required()]}/><CheckBoxFieldname="tos"label="Terms of service"validation={[validators.required(),validators.True('Please accept the TOS'),]}/><NumberInputFieldmin={6}max={22}name="age"label="Age"validation={[validators.required(),validators.numeric(),validators.bigger(10),validators.smallerOrEqual(18),]}/><Box pad="small"><Button type="submit" label="Submit" /></Box></Form>)
Name | Description | Default | |
---|---|---|---|
IFormProps(10 properties) | |||
a11yTitle | Custom title to be used by screen readers string | - | |
focusFirstChild | Whether to focus the first form control on mounting boolean | true | |
object | Initial values of the form data object object | {} | |
onSubmit | A function called when the user successfully submits the form (data: object) => void | undefined | |
onChange | A function invoked when any of the values in the form are changing (name: string, value: any, event: MouseEvent<HTMLElement, MouseEvent> & { value: any; }) => void | undefined | |
onSubmitError | A function invoked when an error occured during submitting (errors: IFormErrors) => void | undefined | |
onValidForm | A function invoked on every change when the form is valid (data: object) => void | undefined | |
onInvalidForm | A function invoked on every change when the form is invalid (data: object) => void | undefined | |
tag | The DOM tag to use for the form string & PolymorphicType | form | |
className | css class name, assigned by styled-components string | - | |
BoxProps(26 properties) |
7 commits
package | imports | peer |
---|---|---|
grommet ^2.15.0 | BoxPropsBox | * |
grommet/utils/object ^2.15.0 | deepMerge | * |
react ^17.0.1 | ReactComponent | * |
file | imports |
---|---|
"./StyledForm" | StyledForm |
"../../utils/dom" | filterByFocusable |
"./FormProps" | IFormPropsIFormContextIFormErrorsIFormFieldProps |
- config
- source
() => {const [changedValue, setChangedValue] = React.useState('');return (<Box pad="small"><FormfocusFirstChild={false}onChange={(name, value) => {console.log(name, value);setChangedValue(value);}}basis="small"><TextInputField label="Text" name="mytextinput" /></Form><Text size="small">{changedValue}</Text></Box>);}
- config
- source
() => (<Box pad="small"><FormfocusFirstChild={false}onSubmit={() => console.log('onSubmit')}onSubmitError={() => console.log('onSubmitError')}basis="small"><TextInputFieldlabel="Text"name="errofield"validation={[validators.required(), validators.minLength(8)]}/></Form></Box>)
valid
- config
- source
() => {const [invalid, setInvalid] = React.useState(undefined);return (<Box pad="small"><FormfocusFirstChild={false}onSubmit={() => console.log('onSubmit')}onInvalidForm={error => setInvalid(error)}onValidForm={() => setInvalid(undefined)}basis="small"><TextInputFieldlabel="Text"name="invalidfield"validation={[validators.required(), validators.minLength(8)]}/></Form><Text size="small">{invalid ? 'invalid' : 'valid'}</Text></Box>);}