Skip to content

Commit

Permalink
wip (laravel#8816)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald authored May 26, 2023
1 parent 437b3b3 commit 2c54cf1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions precognition.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export default function Form() {
onChange={(e) => form.setData('name', e.target.value)}
onBlur={() => form.validate('name')}
/>
{form.invalid('name') ? (<div>{form.errors.name}</div>) : null}
{form.invalid('name') && <div>{form.errors.name}</div>}

<label for="email">Email</label>
<input
Expand All @@ -235,7 +235,7 @@ export default function Form() {
onChange={(e) => form.setData('email', e.target.value)}
onBlur={() => form.validate('email')}
/>
{form.invalid('email') ? (<div>{form.errors.email}</div>) : null}
{form.invalid('email') && <div>{form.errors.email}</div>}

<button>Create User</button>
</form>
Expand All @@ -252,27 +252,27 @@ form.setValidationTimeout(3000);
When a validation request is in-flight, the form's `validating` property will be `true`:

```jsx
{form.validating ? (<div>Validating...</div>) : null}
{form.validating && <div>Validating...</div>}
```

Any validation errors returned during a validation request or a form submission will automatically populate the form's `errors` object:

```jsx
{form.invalid('email') ? (<div>{form.errors.email}</div>) : null}
{form.invalid('email') && <div>{form.errors.email}</div>}
```

You can determine if the form has any errors using the form's `hasErrors` property:

```jsx
{form.hasErrors ? (<div><!-- ... --></div>) : null}
{form.hasErrors && <div><!-- ... --></div>}
```

You may also determine if an input has passed or failed validation by passing the input's name to the form's `valid` and `invalid` functions, respectively:

```jsx
{form.valid('email') ? (<span></span>) : null}
{form.valid('email') && <span></span>}

{form.invalid('email') ? (<span></span>) : null}
{form.invalid('email') && <span></span>}
```

> **Warning**
Expand Down

0 comments on commit 2c54cf1

Please sign in to comment.