Skip to content

Commit

Permalink
Validate only when submitCount > 0, resolve #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Jovert Lota Palonpon committed Apr 9, 2019
1 parent 4371e79 commit fe57dd2
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"plugins": ["react"],
"rules": {
"indent": ["warn", "4"],
"indent": ["warn", 4],
"linebreak-style": ["warn", "unix"],
"quotes": ["warn", "single"],
"semi": ["warn", "always"],
Expand Down
55 changes: 35 additions & 20 deletions resources/js/views/__backoffice/users/Forms/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Account = props => {
onSubmit={handleSubmit}
validateOnBlur={false}
>
{({ values, handleChange, errors, isSubmitting }) => (
{({ values, handleChange, errors, submitCount, isSubmitting }) => (
<Form>
<Typography variant="h6" gutterBottom>
Account Settings
Expand All @@ -42,7 +42,10 @@ const Account = props => {
<Grid item xs={12} sm={12}>
<FormControl
className={classes.formControl}
error={errors.hasOwnProperty('type')}
error={
submitCount > 0 &&
errors.hasOwnProperty('type')
}
>
<InputLabel htmlFor="type">
Type{' '}
Expand All @@ -68,11 +71,12 @@ const Account = props => {
<MenuItem value="user">User</MenuItem>
</Select>

{errors.hasOwnProperty('type') && (
<FormHelperText>
{errors.type}
</FormHelperText>
)}
{submitCount > 0 &&
errors.hasOwnProperty('type') && (
<FormHelperText>
{errors.type}
</FormHelperText>
)}
</FormControl>
</Grid>
</Grid>
Expand All @@ -81,7 +85,10 @@ const Account = props => {
<Grid item xs={12} sm={6}>
<FormControl
className={classes.formControl}
error={errors.hasOwnProperty('email')}
error={
submitCount > 0 &&
errors.hasOwnProperty('email')
}
>
<InputLabel htmlFor="email">
Email{' '}
Expand All @@ -95,18 +102,23 @@ const Account = props => {
onChange={handleChange}
fullWidth
/>
{errors.hasOwnProperty('email') && (
<FormHelperText>
{errors.email}
</FormHelperText>
)}

{submitCount > 0 &&
errors.hasOwnProperty('email') && (
<FormHelperText>
{errors.email}
</FormHelperText>
)}
</FormControl>
</Grid>

<Grid item xs={12} sm={6}>
<FormControl
className={classes.formControl}
error={errors.hasOwnProperty('username')}
error={
submitCount > 0 &&
errors.hasOwnProperty('username')
}
>
<InputLabel htmlFor="username">
Username
Expand All @@ -119,11 +131,13 @@ const Account = props => {
onChange={handleChange}
fullWidth
/>
{errors.hasOwnProperty('username') && (
<FormHelperText>
{errors.username}
</FormHelperText>
)}

{submitCount > 0 &&
errors.hasOwnProperty('username') && (
<FormHelperText>
{errors.username}
</FormHelperText>
)}
</FormControl>
</Grid>
</Grid>
Expand All @@ -145,7 +159,8 @@ const Account = props => {
color="primary"
disabled={
(errors &&
Object.keys(errors).length > 0) ||
Object.keys(errors).length > 0 &&
submitCount > 0) ||
isSubmitting
}
>
Expand Down
Loading

0 comments on commit fe57dd2

Please sign in to comment.