---
url: "https://vueda.dev/v3/reference/api/js/use/useField/functions/useField.md"
title: "useField"
---

# useField

## Overview

Generate and provide a field context for a field.

## Signature

`useField(props, emit, options)`

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| <span id="param-props">props</span> | `object` | yes | The field context's reactive props. |
| <span id="param-emit">emit</span> | `(event: string, args: any[]) => void` | yes | The component emit function. |
| <span id="param-options">options</span> | [UseFieldOptions](/v3/reference/api/js/use/useField/types/UseFieldOptions.md) | no | How the calling component renders the field. |

#### props Properties

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| <span id="param-props-clearServerErrorDependents">clearServerErrorDependents</span> | `string[]` |  |  | Other fields that depend on this field. |
| <span id="param-props-contextless">contextless</span> | `boolean` |  |  | If `true`, the field will ignore the form context and manage its own state. |
| <span id="param-props-formModelName">formModelName</span> | `string` |  |  | The name of the form model for configuration lookup. |
| <span id="param-props-help">help</span> | `string` |  |  | The help text for the field. |
| <span id="param-props-isRequiredViolation">isRequiredViolation</span> | `(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. |
| <span id="param-props-label">label</span> | `string` |  |  | The label for the field. |
| <span id="param-props-modelValue">modelValue</span> | `any` |  |  | The field's external model value (only used in context-less mode). |
| <span id="param-props-name">name</span> | `string` |  |  | The name of the field. |
| <span id="param-props-readOnly">readOnly</span> | `boolean` |  |  | Whether the field is read-only. |
| <span id="param-props-required">required</span> | `boolean` |  |  | Whether the field is required. |
| <span id="param-props-requiredMessage">requiredMessage</span> | `string` |  |  | The message to display if the field is required and empty. |
| <span id="param-props-shouldRequireFn">shouldRequireFn</span> | `(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. |
| <span id="param-props-validate">validate</span> | `(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. |
| <span id="param-props-validationDependencies">validationDependencies</span> | `string[]` |  |  | Other fields that this field depends on. |

### Returns

[FieldContext](/v3/reference/api/js/use/useField/types/FieldContext.md)

The field context object.

## Source

`client/lib/use/useField.js:292`
