Skip to content

Commit

Permalink
Merge pull request #1583 from danieldkim42/dk.1581
Browse files Browse the repository at this point in the history
feat: refactor ValidationTextField to accept required property
  • Loading branch information
danieldkim42 authored Feb 12, 2024
2 parents 6f58556 + a6325d3 commit 5e2edee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion client/src/components/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export const simpleInputs = [
name: 'hflaWebsiteUrl',
type: 'text',
placeholder: 'htttps://hackforla.org/projects/',
disabled: false
disabled: false,
required: false
},
];

Expand Down
15 changes: 10 additions & 5 deletions client/src/components/parts/form/ValidatedTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ function ValidatedTextField({
locationRadios,
input,
}) {
const registerObj = {
...register(input.name, {
required: `${input.name} is required`,
const inputObj = {
pattern:
input.name === 'location'
? locationType === 'remote'
Expand All @@ -39,8 +37,15 @@ function ValidatedTextField({
message: input.addressError,
}
: { value: input.value, message: input.errorMessage },
}
)}
};
if ('required' in input && input.required === false) {
// if required is set to false, don't add required attribute to object
} else {
inputObj.required = `${input.name} is required`;
}
const registerObj = {
...register(input.name, inputObj),
}

return (
<Box sx={{ mb: 1 }} key={input.name}>
Expand Down

0 comments on commit 5e2edee

Please sign in to comment.