-
Notifications
You must be signed in to change notification settings - Fork 0
Form validation #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Form validation #28
Conversation
…ActionButtons, HomePage and Header components.
… configuration. Added rule class-name-format rule.
| if (!this.canSubmitForm()) { | ||
| return; | ||
| } | ||
| let validation = this.validator.validate(this.state.user); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see validation being reassingned, use const instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
| const invalidPhone = validation.phone && | ||
| !get(validation, 'phone.isValid'); | ||
| const invalidSkypeId = validation.skypeId && | ||
| !get(validation, 'skypeId.isValid'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't a default return value for get needed? just in case
| invalid={isNameInvalid} | ||
| feedback={errors.name} | ||
| invalid={invalidName} | ||
| feedback={get(validation, 'name.message')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here get(validation, 'name.message, '')
| invalid={isEmailInvalid} | ||
| feedback={emailFeedback} | ||
| invalid={invalidEmail} | ||
| feedback={get(validation, 'email.message')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
| placeholder="skype Id" | ||
| required={true} | ||
| invalid={invalidSkypeId} | ||
| feedback={get(validation, 'skypeId.message')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
| placeholder="Phone Number" | ||
| required={true} | ||
| invalid={invalidPhone} | ||
| feedback={get(validation, 'phone.message')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
| ...validationSettings.email, | ||
| ...validationSettings.skypeId, | ||
| ...validationSettings.phone | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will need lodash cloneDeep here (unless you spread each nested object), spread will clone first level attributes. Nested Objects will be passed by reference and unexpectedly mutated.
yarn add lodash.cloneDeep
and here
import cloneDeep from 'lodash.cloneDeep'
webapp/package.json
Outdated
| "sass-loader": "^7.0.3", | ||
| "style-loader": "^0.21.0", | ||
| "uglifyjs-webpack-plugin": "1.2.5", | ||
| "validator": "^10.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to dependencies, it's part of the code bundle.
| import FormInput from '../../common/form/FormInput'; | ||
|
|
||
| import { Row } from 'reactstrap'; | ||
| import { get } from 'lodash'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with
import get from 'lodash.get';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to do the same with lodash.cloneDeep but I am having some issues: warning webpack-bundle-analyzer > bfj-node4@5.3.1: Switch to the bfj package for fixes and new
features!
| }); | ||
|
|
||
| return { isValid: true, ...validation }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a semi colon
| this.toggle(); | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this callback to a method to simplfy this handler, and prefer use arrow callback.
Form validation - In progress