Skip to content

Commit b95ae6f

Browse files
authored
Merge pull request #8908 from marmelab/use-input-validation
Simplify useInput validation
2 parents cd2e32c + 44eaf52 commit b95ae6f

File tree

7 files changed

+18
-24
lines changed

7 files changed

+18
-24
lines changed

examples/simple/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"react": "^17.0.0",
2626
"react-admin": "^4.10.2",
2727
"react-dom": "^17.0.0",
28-
"react-hook-form": "^7.40.0",
28+
"react-hook-form": "^7.43.9",
2929
"react-query": "^3.32.1",
3030
"react-router": "^6.1.0",
3131
"react-router-dom": "^6.1.0"

packages/ra-core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"ignore-styles": "~5.0.1",
4040
"react": "^17.0.0",
4141
"react-dom": "^17.0.0",
42-
"react-hook-form": "^7.40.0",
42+
"react-hook-form": "^7.43.9",
4343
"react-router": "^6.1.0",
4444
"react-router-dom": "^6.1.0",
4545
"react-test-renderer": "^16.9.0 || ^17.0.0",
@@ -51,7 +51,7 @@
5151
"history": "^5.1.0",
5252
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
5353
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0",
54-
"react-hook-form": "^7.40.0",
54+
"react-hook-form": "^7.43.9",
5555
"react-router": "^6.1.0",
5656
"react-router-dom": "^6.1.0"
5757
},

packages/ra-core/src/form/useInput.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
useController,
66
UseControllerProps,
77
UseControllerReturn,
8-
useFormContext,
98
UseFormStateReturn,
109
} from 'react-hook-form';
1110
import get from 'lodash/get';
@@ -45,7 +44,6 @@ export const useInput = <ValueType = any>(
4544
const formGroups = useFormGroups();
4645
const record = useRecordContext();
4746
const getValidationErrorMessage = useGetValidationErrorMessage();
48-
const formContext = useFormContext();
4947

5048
useEffect(() => {
5149
if (!formGroups || formGroupName == null) {
@@ -71,13 +69,9 @@ export const useInput = <ValueType = any>(
7169
name: finalName,
7270
defaultValue: get(record, source, defaultValue),
7371
rules: {
74-
validate: async value => {
72+
validate: async (value, values) => {
7573
if (!sanitizedValidate) return true;
76-
const error = await sanitizedValidate(
77-
value,
78-
formContext.getValues(),
79-
props
80-
);
74+
const error = await sanitizedValidate(value, values, props);
8175

8276
if (!error) return true;
8377
return getValidationErrorMessage(error);

packages/ra-input-rich-text/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"ra-ui-materialui": "^4.10.2",
5656
"react": "^17.0.0",
5757
"react-dom": "^17.0.0",
58-
"react-hook-form": "^7.40.0",
58+
"react-hook-form": "^7.43.9",
5959
"rimraf": "^3.0.2",
6060
"typescript": "^4.4.0"
6161
},

packages/ra-ui-materialui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"ra-language-english": "^4.10.2",
4141
"react": "^17.0.0",
4242
"react-dom": "^17.0.0",
43-
"react-hook-form": "^7.40.0",
43+
"react-hook-form": "^7.43.9",
4444
"react-router": "^6.1.0",
4545
"react-router-dom": "^6.1.0",
4646
"react-test-renderer": "~16.8.6",

packages/react-admin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"ra-i18n-polyglot": "^4.10.2",
4646
"ra-language-english": "^4.10.2",
4747
"ra-ui-materialui": "^4.10.2",
48-
"react-hook-form": "^7.40.0",
48+
"react-hook-form": "^7.43.9",
4949
"react-router": "^6.1.0",
5050
"react-router-dom": "^6.1.0"
5151
},

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18911,7 +18911,7 @@ __metadata:
1891118911
query-string: ^7.1.1
1891218912
react: ^17.0.0
1891318913
react-dom: ^17.0.0
18914-
react-hook-form: ^7.40.0
18914+
react-hook-form: ^7.43.9
1891518915
react-is: ^17.0.2
1891618916
react-query: ^3.32.1
1891718917
react-router: ^6.1.0
@@ -18924,7 +18924,7 @@ __metadata:
1892418924
history: ^5.1.0
1892518925
react: ^16.9.0 || ^17.0.0 || ^18.0.0
1892618926
react-dom: ^16.9.0 || ^17.0.0 || ^18.0.0
18927-
react-hook-form: ^7.40.0
18927+
react-hook-form: ^7.43.9
1892818928
react-router: ^6.1.0
1892918929
react-router-dom: ^6.1.0
1893018930
languageName: unknown
@@ -19073,7 +19073,7 @@ __metadata:
1907319073
ra-ui-materialui: ^4.10.2
1907419074
react: ^17.0.0
1907519075
react-dom: ^17.0.0
19076-
react-hook-form: ^7.40.0
19076+
react-hook-form: ^7.43.9
1907719077
rimraf: ^3.0.2
1907819078
typescript: ^4.4.0
1907919079
peerDependencies:
@@ -19166,7 +19166,7 @@ __metadata:
1916619166
react-dom: ^17.0.0
1916719167
react-dropzone: ^12.0.4
1916819168
react-error-boundary: ^3.1.4
19169-
react-hook-form: ^7.40.0
19169+
react-hook-form: ^7.43.9
1917019170
react-query: ^3.32.1
1917119171
react-router: ^6.1.0
1917219172
react-router-dom: ^6.1.0
@@ -19361,7 +19361,7 @@ __metadata:
1936119361
ra-i18n-polyglot: ^4.10.2
1936219362
ra-language-english: ^4.10.2
1936319363
ra-ui-materialui: ^4.10.2
19364-
react-hook-form: ^7.40.0
19364+
react-hook-form: ^7.43.9
1936519365
react-router: ^6.1.0
1936619366
react-router-dom: ^6.1.0
1936719367
rimraf: ^3.0.2
@@ -19552,12 +19552,12 @@ __metadata:
1955219552
languageName: node
1955319553
linkType: hard
1955419554

19555-
"react-hook-form@npm:^7.40.0":
19556-
version: 7.40.0
19557-
resolution: "react-hook-form@npm:7.40.0"
19555+
"react-hook-form@npm:^7.43.9":
19556+
version: 7.43.9
19557+
resolution: "react-hook-form@npm:7.43.9"
1955819558
peerDependencies:
1955919559
react: ^16.8.0 || ^17 || ^18
19560-
checksum: 16e071ba3a11977948d7b0cbb6a84db80823465740210d3ea58d7cb93813e8771a585e4ffb82f53b24ac5ea43a6fe37da07b42d41aecda7b160dc68d68e50781
19560+
checksum: 5aab031ae15b32daffb45abe32e00c9d66c511348b68589d4faa6c2309db54b9d2f738b400319b0c2ea87dfd5d85f3760393feafe2bf7a97d608aa736934151f
1956119561
languageName: node
1956219562
linkType: hard
1956319563

@@ -21006,7 +21006,7 @@ __metadata:
2100621006
react-admin: ^4.10.2
2100721007
react-app-polyfill: ^1.0.4
2100821008
react-dom: ^17.0.0
21009-
react-hook-form: ^7.40.0
21009+
react-hook-form: ^7.43.9
2101021010
react-query: ^3.32.1
2101121011
react-router: ^6.1.0
2101221012
react-router-dom: ^6.1.0

0 commit comments

Comments
 (0)