Skip to content

Commit fe57dd2

Browse files
author
Jovert Lota Palonpon
committed
Validate only when submitCount > 0, resolve #22
1 parent 4371e79 commit fe57dd2

File tree

6 files changed

+284
-237
lines changed

6 files changed

+284
-237
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"plugins": ["react"],
1919
"rules": {
20-
"indent": ["warn", "4"],
20+
"indent": ["warn", 4],
2121
"linebreak-style": ["warn", "unix"],
2222
"quotes": ["warn", "single"],
2323
"semi": ["warn", "always"],

resources/js/views/__backoffice/users/Forms/Account.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Account = props => {
3232
onSubmit={handleSubmit}
3333
validateOnBlur={false}
3434
>
35-
{({ values, handleChange, errors, isSubmitting }) => (
35+
{({ values, handleChange, errors, submitCount, isSubmitting }) => (
3636
<Form>
3737
<Typography variant="h6" gutterBottom>
3838
Account Settings
@@ -42,7 +42,10 @@ const Account = props => {
4242
<Grid item xs={12} sm={12}>
4343
<FormControl
4444
className={classes.formControl}
45-
error={errors.hasOwnProperty('type')}
45+
error={
46+
submitCount > 0 &&
47+
errors.hasOwnProperty('type')
48+
}
4649
>
4750
<InputLabel htmlFor="type">
4851
Type{' '}
@@ -68,11 +71,12 @@ const Account = props => {
6871
<MenuItem value="user">User</MenuItem>
6972
</Select>
7073

71-
{errors.hasOwnProperty('type') && (
72-
<FormHelperText>
73-
{errors.type}
74-
</FormHelperText>
75-
)}
74+
{submitCount > 0 &&
75+
errors.hasOwnProperty('type') && (
76+
<FormHelperText>
77+
{errors.type}
78+
</FormHelperText>
79+
)}
7680
</FormControl>
7781
</Grid>
7882
</Grid>
@@ -81,7 +85,10 @@ const Account = props => {
8185
<Grid item xs={12} sm={6}>
8286
<FormControl
8387
className={classes.formControl}
84-
error={errors.hasOwnProperty('email')}
88+
error={
89+
submitCount > 0 &&
90+
errors.hasOwnProperty('email')
91+
}
8592
>
8693
<InputLabel htmlFor="email">
8794
Email{' '}
@@ -95,18 +102,23 @@ const Account = props => {
95102
onChange={handleChange}
96103
fullWidth
97104
/>
98-
{errors.hasOwnProperty('email') && (
99-
<FormHelperText>
100-
{errors.email}
101-
</FormHelperText>
102-
)}
105+
106+
{submitCount > 0 &&
107+
errors.hasOwnProperty('email') && (
108+
<FormHelperText>
109+
{errors.email}
110+
</FormHelperText>
111+
)}
103112
</FormControl>
104113
</Grid>
105114

106115
<Grid item xs={12} sm={6}>
107116
<FormControl
108117
className={classes.formControl}
109-
error={errors.hasOwnProperty('username')}
118+
error={
119+
submitCount > 0 &&
120+
errors.hasOwnProperty('username')
121+
}
110122
>
111123
<InputLabel htmlFor="username">
112124
Username
@@ -119,11 +131,13 @@ const Account = props => {
119131
onChange={handleChange}
120132
fullWidth
121133
/>
122-
{errors.hasOwnProperty('username') && (
123-
<FormHelperText>
124-
{errors.username}
125-
</FormHelperText>
126-
)}
134+
135+
{submitCount > 0 &&
136+
errors.hasOwnProperty('username') && (
137+
<FormHelperText>
138+
{errors.username}
139+
</FormHelperText>
140+
)}
127141
</FormControl>
128142
</Grid>
129143
</Grid>
@@ -145,7 +159,8 @@ const Account = props => {
145159
color="primary"
146160
disabled={
147161
(errors &&
148-
Object.keys(errors).length > 0) ||
162+
Object.keys(errors).length > 0 &&
163+
submitCount > 0) ||
149164
isSubmitting
150165
}
151166
>

0 commit comments

Comments
 (0)