Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updating docs-field-api removing old doc and updating to new pr… #423

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions docs/reference/fieldApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Field API

### Creating a new FieldApi Instance

> Some of these docs may be inaccurate due to an API shift in `0.11.0`. If you're interested in helping us fix these issues, please [join our Discord](https://tlinz.com/discord) and reach out in the `#form` channel.


Normally, you will not need to create a new `FieldApi` instance directly. Instead, you will use a framework hook/function like `useField` or `createField` to create a new instance for you that utilizes your frameworks reactivity model. However, if you need to create a new instance manually, you can do so by calling the `new FieldApi` constructor.

Expand All @@ -26,33 +26,57 @@ An object type representing the options for a field in a form.
```
- An optional default value for the field.
- ```tsx
form?: FormApi<TFormData>
defaultMeta?: Partial<FieldMeta>
```
- An optional reference to the form API instance.
- An optional object with default metadata for the field.

- ```tsx
validate?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError | Promise<ValidationError>
onMount?: (formApi: FieldApi<TData, TFormData>) => void
```
- An optional validation function for the field.
- An optional function that takes a param of `formApi` which is a generic type of `TData` and `TFormData`

- ```tsx
validatePristine?: boolean
onChange?: ValidateFn<TData, TFormData>
```
- An optional flag indicating whether to validate the field when it is pristine (untouched).
- An optional property that takes a `ValidateFn` which is a generic of `TData` and `TFormData`

- ```tsx
defaultMeta?: Partial<FieldMeta>
onChangeAsync?: ValidateAsyncFn<TData, TFormData>
```
- An optional object with default metadata for the field.
- An optional property similar to `onChange` but async validation


- ```tsx
validateOn?: ValidationCause
onChangeAsyncDebounceMs?: number
```
- An optional string indicating when to perform field validation.
- An optional number to represent how long the `onChangeAsync` should wait before running
- If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds

- ```tsx
validateAsyncOn?: ValidationCause
onBlur?: ValidateFn<TData, TFormData>
```
- An optional string indicating when to perform async field validation.
- An optional function, when that run when subscribing to blur event of input

- ```tsx
validateAsyncDebounceMs?: number
onBlurAsync?: ValidateAsyncFn<TData, TFormData>
```
- An optional function that takes a `ValidateFn` which is a generic of `TData` and `TFormData` happens async

```tsx
onBlurAsyncDebounceMs?: number
```
- An optional number to represent how long the `onBlurAsyncDebounceMs` should wait before running
- If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds

```tsx
onSubmitAsync?: number
```
- If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds.
- If set to a number larger than 0, will debounce the async validation event by this length of time in milliseconds






### `ValidationCause`

Expand Down