Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
martincai8 authored Oct 1, 2024
2 parents 76a0aaf + 6b407d2 commit f47f57a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/utility/Validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const validateFormSection = (change, section, fields) => {
(typeof value === 'object' && Object.values(value).includes(true))
) {
// check for other
if (value.other === true) {
if (value.other === true || value === 'Other') {
if (
!(toOtherCamelCase(key) in change) ||
!validateStringNotEmpty(change[toOtherCamelCase(key)])
Expand All @@ -193,10 +193,19 @@ export const validateFormSection = (change, section, fields) => {
}

if (!validators[section][key]) {
const { error: noEmptyError, message: noEmptyMessage } = noEmptyFunction(value)
if (noEmptyError) {
hasError = true
errorMessage = noEmptyMessage
// if value is an object, go noNoneFunction; else go noEmptyFunction
if (typeof value === 'object') {
const { error: noNoneError, message: noNoneMessage } = noNoneFunction(value)
if (noNoneError) {
hasError = true
errorMessage = noNoneMessage
}
} else {
const { error: noEmptyError, message: noEmptyMessage } = noEmptyFunction(value)
if (noEmptyError) {
hasError = true
errorMessage = noEmptyMessage
}
}
} else {
const { error: validatorError, message: validatorMessage } = validators[section][key](
Expand All @@ -223,7 +232,6 @@ export const validateFormSection = (change, section, fields) => {
newErrors[key] = hasError ? errorMessage : false
})
}

return newErrors
}

Expand Down Expand Up @@ -273,7 +281,7 @@ const validators = {
legalFirstName: noEmptyFunction,
legalLastName: noEmptyFunction,
preferredName: noEmptyFunction,
gender: noEmptyFunction,
gender: noNoneFunction,
identifyAsUnderrepresented: noEmptyFunction,
pronouns: noNoneFunction,
ethnicity: noNoneFunction,
Expand Down

0 comments on commit f47f57a

Please sign in to comment.