Skip to content
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

Disable the submit button if required form fields are not filled out #4272

Merged
merged 4 commits into from
Jul 30, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,31 @@ class CompanyStep extends React.Component {
hasNoConnectionToCannabis: lodashGet(props, ['achData', 'hasNoConnectionToCannabis'], false),
password: '',
};

// These fields need to be filled out in order to submit the form
this.requiredFields = [
'companyName',
'addressStreet',
'addressCity',
'addressState',
'addressZipCode',
'website',
'companyTaxID',
'incorporationDate',
'industryCode',
'password',
];
}

/**
* @returns {Boolean}
*/
validate() {
if (!this.state.password.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we leave these in?
B/c the button will be disabled, but what if someone hits return or "Done" on mobile or whatever, won't that still submit the form and bypass the button being disabled?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically I don't think we should rely on the button being enabled/disabled as a sign that the input is valid or not.

Growl.error(this.props.translate('common.passwordCannotBeBlank'));
return false;
}

if (!isValidAddress(this.state.addressStreet)) {
Growl.error(this.props.translate('bankAccount.error.addressStreet'));
return false;
}

if (this.state.addressState === '') {
Growl.error(this.props.translate('bankAccount.error.addressState'));
return false;
}

if (!isValidZipCode(this.state.addressZipCode)) {
Growl.error(this.props.translate('bankAccount.error.zipCode'));
return false;
Expand Down Expand Up @@ -111,6 +115,8 @@ class CompanyStep extends React.Component {
render() {
const shouldDisableCompanyName = Boolean(this.props.achData.bankAccountID && this.props.achData.companyName);
const shouldDisableCompanyTaxID = Boolean(this.props.achData.bankAccountID && this.props.achData.companyTaxID);
const shouldDisableSubmitButton = this.requiredFields
.reduce((acc, curr) => acc || !this.state[curr].trim(), false);
return (
<>
<HeaderWithCloseButton
Expand Down Expand Up @@ -253,6 +259,7 @@ class CompanyStep extends React.Component {
onPress={this.submit}
style={[styles.w100]}
text={this.props.translate('common.saveAndContinue')}
isDisabled={shouldDisableSubmitButton}
/>
</FixedFooter>
</>
Expand Down