Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jean-Louis Leysens <jloleysens@gmail.com>
Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
  • Loading branch information
3 people committed Feb 18, 2021
1 parent 869267e commit 229947d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Expand Up @@ -120,7 +120,7 @@ export const ReusableValidations = () => {

## Asynchronous validation

You can mix synchronous and asynchronous validations. Although it is usually better to first declare the synchronous one(s), this way if any of those ones fails, the asynchronous validation is not executed.
You can mix synchronous and asynchronous validations. Although it is usually better to first declare the synchronous one(s), this way if any of those fail, the asynchronous validation is not executed.

In the example below, if you enter "bad" in the field, the asynchronous validation will fail.

Expand Down Expand Up @@ -366,4 +366,4 @@ export const ValidationWithTypeComboBoxField = () => {
};
```
Much better! :blush:
Much better! :blush:
Expand Up @@ -6,7 +6,7 @@ sidebar_label: About

## Presentation

The form library helps us building forms efficiently by providing a system whose main task is (1) to abstract away the state management of fields values and validity and (2) running validations on the fields when their values change.
The form library helps us build forms efficiently by providing a system whose main task is (1) to abstract away the state management of fields values and validity and (2) running validations on the fields when their values change.

The system is composed of **three parts**:

Expand Down
Expand Up @@ -4,9 +4,11 @@ title: Components
sidebar_label: Components
---

The core of the form lib is UI agnostic. It can be used with any React UI library to render the form fields. As in Elastic we use [the EUI framework](https://elastic.github.io/eui), we have created components that connect our `FieldHook` to the `<EuiFormRow/>` and its corresponding EUI field.
The core of the form lib is UI agnostic. It can be used with any React UI library to render the form fields.

You can import those component and directly use them as `component` prop on your `<UseField />`.
At Elastic we use [the EUI framework](https://elastic.github.io/eui). We created components that connect our `FieldHook` to the `<EuiFormRow/>` and its corresponding EUI field.

You can import these components and pass them to the `component` prop on your `<UseField />`.

```js
import { Form, useForm, UseField, TextField, ToggleField } from '<path-to-form-lib>';
Expand Down Expand Up @@ -122,4 +124,4 @@ export const MyFormComponent = () => {
</Form>
);
};
```
```
Expand Up @@ -6,7 +6,7 @@ sidebar_label: Validators

As you have seen in the `<UseField />` configuration, the validations are objects with [a required `validator` function](../core/use_field#validator-required) attached to them.

After building many forms, we have realized that we are doing almost all the time the same validation on a field: is the field empty? does it contain a character not allowed?, does it start with an invalid character? is it valid JSON? ...
After building many forms, we have realized that we are often doing the same validation on a field: is the field empty? does it contain a character not allowed?, does it start with an invalid character? is it valid JSON? ...

So instead of reinventing the wheel on each form we have exported to most common validators as reusable function that you can use directly in your field validations. Some validator might expose directly the handler to validate, some others expose a function that you need to call with some parameter and you will receive the validator back.

Expand Down

0 comments on commit 229947d

Please sign in to comment.