useField
Overview
Generate and provide a field context for a field.
Signature
useField(props, emit)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| props | object | yes | The field context's reactive props. |
| emit | (event: string, args: any[]) => void | yes | The component emit function. |
props Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| clearServerErrorDependents | string[] | Other fields that depend on this field. | ||
| contextless | boolean | If true, the field will ignore the form context and manage its own state. | ||
| formModelName | string | The name of the form model for configuration lookup. | ||
| help | string | The help text for the field. | ||
| isRequiredViolation | (value: any) => boolean | A custom function that checks whether the current field value violates the required rule (i.e. "is a violation"). The default behavior returns true when the value is null, undefined, an empty string, false, or 0. | ||
| label | string | The label for the field. | ||
| modelValue | any | The field's external model value (only used in context-less mode). | ||
| name | string | The name of the field. | ||
| readOnly | boolean | Whether the field is read-only. | ||
| required | boolean | Whether the field is required. | ||
| requiredMessage | string | The message to display if the field is required and empty. | ||
| shouldRequireFn | (validationDependencies: object) => boolean | A custom function that determines whether the field should be marked as required based on its configuration or validationDependencies (i.e. "can be required"). When provided, this overrides the explicit required prop. | ||
| validate | (value: any, validationDependencies: object) => boolean | A custom validation function for the field. This function should return true when the field is valid. Otherwise, it should return a string with the desired error message. | ||
| validationDependencies | string[] | Other fields that this field depends on. |
Returns
The field context object.
Source
client/lib/use/useField.js:282