Skip to content

useField

Overview

Generate and provide a field context for a field.

Signature

useField(props, emit)

Parameters

NameTypeRequiredDescription
propsobjectyesThe field context's reactive props.
emit(event: string, args: any[]) => voidyesThe component emit function.

props Properties

NameTypeRequiredDefaultDescription
clearServerErrorDependentsstring[]Other fields that depend on this field.
contextlessbooleanIf true, the field will ignore the form context and manage its own state.
formModelNamestringThe name of the form model for configuration lookup.
helpstringThe help text for the field.
isRequiredViolation(value: any) => booleanA 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.
labelstringThe label for the field.
modelValueanyThe field's external model value (only used in context-less mode).
namestringThe name of the field.
readOnlybooleanWhether the field is read-only.
requiredbooleanWhether the field is required.
requiredMessagestringThe message to display if the field is required and empty.
shouldRequireFn(validationDependencies: object) => booleanA 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) => booleanA 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.
validationDependenciesstring[]Other fields that this field depends on.

Returns

FieldContext

The field context object.

Source

client/lib/use/useField.js:282

Documents matching: server v3.0.0a1.post1client v3.0.0-alpha.2