Skip to content

Commit 68d2425

Browse files
authored
fix: TextField validateOnChange with defaultValue executed on start (#2411)
* fix: TextField validateOnChange on web * code review
1 parent 5d75614 commit 68d2425

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"scripts": {
1717
"start": "watchman watch-del-all && export DEV_MODE=true && react-native start",
18+
"start:web": "npm --prefix webDemo run start",
1819
"ios": "react-native run-ios",
1920
"android": "react-native run-android",
2021
"iPad": "react-native run-ios --simulator='iPad Pro (9.7 inch)'",

src/incubator/TextField/useFieldState.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export default function useFieldState({
2323
if (Constants.isWeb && !props.value && props.defaultValue && props.defaultValue !== value) {
2424
setValue(props.defaultValue);
2525

26-
if (validateOnChange) {
26+
if (validateOnStart) {
2727
validateField(props.defaultValue);
2828
}
2929
}
3030

3131
/* On purpose listen only to props.defaultValue change */
3232
/* eslint-disable-next-line react-hooks/exhaustive-deps*/
33-
}, [props.defaultValue, validateOnChange]);
33+
}, [props.defaultValue, validateOnStart]);
3434

3535
useEffect(() => {
3636
if (validateOnStart) {
@@ -42,7 +42,7 @@ export default function useFieldState({
4242
if (props.value !== value) {
4343
setValue(props.value);
4444

45-
if (validateOnChange) {
45+
if (validateOnChange && value !== props.defaultValue) {
4646
validateField(props.value);
4747
}
4848
}

webDemo/src/App.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,14 @@ const itemsToRender: ItemToRender[] = [
173173
migrate
174174
defaultValue={defaultValue}
175175
containerStyle={{marginBottom: 10}}
176-
placeholder="type here..."
176+
placeholder="Enter your email..."
177+
validationMessage={['Email is required', 'Email is invalid']}
178+
validationMessagePosition={'top'}
179+
enableErrors
180+
validate={['required', 'email']}
181+
validateOnStart={false}
182+
validateOnChange
183+
validateOnBlur={false}
177184
onChangeText={(text: string) => {
178185
console.log(text);
179186
}}

0 commit comments

Comments
 (0)