forked from react-hook-form/react-hook-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📮 fix(react-hook-form#11239): Set fields disabled state based on form…
… and field disabled (react-hook-form#11241) * fix(react-hook-form#11239): Set fields disabled state based on form and field disabled prop * fix(react-hook-form#11239): If-check and unit test * Update createFormControl.ts --------- Co-authored-by: Thomas De Bock <thomas.de.bock@persgroep.net> Co-authored-by: Beier (Bill) <bluebill1049@hotmail.com>
- Loading branch information
1 parent
1763831
commit fc76251
Showing
5 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { useForm } from "react-hook-form"; | ||
|
||
const toggle = (state: boolean) => !state; | ||
|
||
export default function DisabledFields() { | ||
const [formDisabled, setFormDisabled] = React.useState(false); | ||
const [firstDisabled, setFirstDisabled] = React.useState(false); | ||
const [secondDisabled, setSecondDisabled] = React.useState(true); | ||
const { register } = useForm({ disabled: formDisabled }); | ||
|
||
return ( | ||
<form> | ||
<button type="button" onClick={() => setFormDisabled(toggle)}>Toggle form</button> | ||
<button type="button" onClick={() => setFirstDisabled(toggle)}>Toggle Field 1</button> | ||
<button type="button" onClick={() => setSecondDisabled(toggle)}>Toggle Field 2</button> | ||
|
||
<input placeholder="Field 1" {...register('first', { disabled: firstDisabled }) } /> | ||
<input placeholder="Field 2" {...register('second', { disabled: secondDisabled }) } /> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters