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: adjust wording and fix some errors #12

Merged
merged 3 commits into from Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/api/use-field-array.md
@@ -1,6 +1,6 @@
# useFieldArray

`useFieldArray()` is a custom Vue composition api that will return specific fields values, meta (state), attributes and provides common operation helpers, you can also add validation for those fields.
`useFieldArray()` is a custom Vue composition api that will return values, meta (state), attributes of specific field and provides common operation helpers, you can also add validation to validate the values in it.

## Usage

Expand Down Expand Up @@ -52,15 +52,15 @@ Name of the field array.

```ts
interface UseFieldArrayOptions<Value> {
// This function allows you to write your logic to validate your field,
// This function allows you to write your logic to validate your values in this field,
// this is optional.
validate?: FieldArrayValidator<Value[]>;
}

type FieldArrayValidator<Value extends Array<any>> = (value: Value) => FormErrors<Value> | void | Promise<FormErrors<Value> | void>;
```

The `validate` is a **field level** validation. This property accepts the field array's `value` as an argument. You can return an array or an undefined to determine whether or not this filed array is a valid value.
The `validate` is a **field level** validation. This property accepts the `values` of this field as an argument. You can return an array or an undefined to determine whether the values in it is valid or not.

## Returns

Expand All @@ -82,9 +82,9 @@ This array contains every entry of field's key, value, meta and attrs.
}
```

`useFieldArray` automatically generates a unique identifier named `key` which is used for key prop. For more information why this is required: [Maintaining State with key](https://vuejs.org/guide/essentials/list.html#maintaining-state-with-key)
`useFieldArray` automatically generates an unique identifier named `key` which is used for key prop. For more information why this is required: [Maintaining State with key](https://vuejs.org/guide/essentials/list.html#maintaining-state-with-key)

The `field.key` must be added as the component key to prevent re-renders breaking the fields.
The `field.key` must be added as the key of component to prevent the field from being broken by re-rendering.

```vue
<template>
Expand Down Expand Up @@ -132,7 +132,7 @@ console.log(fields.value.map(field => field.value))

### swap

Swap items position.
Swap the position of the item.

- Type `(indexA: number, indexB: number) => void`

Expand All @@ -149,7 +149,7 @@ console.log(fields.value.map(field => field.value))

### remove

Remove item at the specified position, or remove all when no index provided.
Remove the item by it index, or remove all when no index is provided.

- Type `(index?: number) => void`

Expand All @@ -170,7 +170,7 @@ console.log(fields.value.map(field => field.value))

### move

Move item to another position.
Move the item to another position.

- Type `(from: number, to: number) => void`

Expand All @@ -187,7 +187,7 @@ console.log(fields.value.map(field => field.value))

### insert

Insert item at the specified position.
Insert an item at the specified position.

- Type `(index: number, value: Value) => void`

Expand All @@ -204,7 +204,7 @@ console.log(fields.value.map(field => field.value))

### update

Update int at the specified position.
Update the item at the specified position.

- Type `(index: number, value: Value) => void`

Expand Down
38 changes: 19 additions & 19 deletions docs/api/use-field.md
@@ -1,6 +1,6 @@
# useField

`useField()` is a custom Vue composition api that will return specific field value, meta (state) and attributes, you can also add validation for that field.
`useField(name: MaybeRef<string>, options?: UseFieldOptions<Value>)` is a custom Vue composition api that will return the value, meta (state) and attributes of a specific field, you can also add validation to it.

## Usage

Expand Down Expand Up @@ -31,7 +31,7 @@ The name of a specific field. Its type can be `string` or `Ref<string>`

- Type `MaybeRef<string>`

If you want to create a custom component in your application, such as `<TextField />`, you should use `Ref<string>` to retain reactivity of `props.name`. as follows:
If you want to create a custom component in your application, such as `<TextField />`, you should use `Ref<string>` to retain reactivity for `props.name`. as follows:

```vue
<script setup lang="ts">
Expand All @@ -50,7 +50,7 @@ const { value } = useField<string>(nameRef)
</script>
```

This is useful when you have a dynamic field name, such as name that is generated with a `v-for` loop.
This is useful when you have a dynamic field name. e.g. the name is generated using a `v-for` loop.

```vue
<template>
Expand All @@ -64,53 +64,53 @@ This is useful when you have a dynamic field name, such as name that is generate

- Type

```ts
interface UseFieldOptions<Value> = {
// This function allows you to write your logic to validate your field,
// this is optional.
validate?: FieldValidator<Value>;
};
```ts
interface UseFieldOptions<Value> {
// This function allows you to write your logic to validate your field,
// this is optional.
validate?: FieldValidator<Value>;
};

type FieldValidator<Value> = (value: Value) => string | void | Promise<string | void>;
```
type FieldValidator<Value> = (value: Value) => string | void | Promise<string | void>;
```

The `validate` is a **field level** validation. This property accepts the field's `value` as an argument. You can return a string or an undefined value to determine whether or not this is a valid value, the string you return will be the error message for this field.
The `validate` is a **field level** validation. This property accepts the field's `value` as an argument. You can return a string or an undefined value to determine whether this value is valid or not, the string you return will be the error message for this field.

## Returns

### value

Current field value.
Current field's value.

- Type `Ref<Value>`

### error

Field error message.
Current field's error message.

- Type `ComputedRef<string>`

### touched

Return `true` after input first blur.
Returns `true` after the field has been blurred for the first time.

- Type `ComputedRef<boolean>`

### dirty

Return `true` if current field value are not equal initial value.
Return `true` if current field's value are not equal to initial value.

- Type `ComputedRef<string>`

### attrs

`attrs` is attributes that need to be bound on the field.
`attrs` is attributes that need to be bound to the field.

- Type `ComputedRef<FieldAttrs>`

```ts
interface FieldAttrs = {
// Field's name that we pass by.
interface FieldAttrs {
// Field's name that you passed earlier.
name: string;
onBlur(event: Event): void;
onChange(): void;
Expand Down
4 changes: 2 additions & 2 deletions docs/api/use-form-context.md
@@ -1,6 +1,6 @@
# useFormContext

`useFormContext()` is a custom Vue composition api that allow you access the form context. This is useful with deeply nested component structures.
`useFormContext()` is a custom Vue composition api that allow you to access the form context. This is useful with nested component in deep structures.

## Usage

Expand All @@ -21,7 +21,7 @@ const { handleSubmit } = useForm({
<NestedTextField />
<button type="submit">
Submit
<button>
</button>
</form>
</template>
```
Expand Down