Skip to content

Commit

Permalink
fw-5107, fix error messages for text array field (#179)
Browse files Browse the repository at this point in the history
Co-authored-by: Guy McAuliffe <38873380+gmcauliffe@users.noreply.github.com>
  • Loading branch information
sarahfirstvoices and gmcauliffe authored Oct 26, 2023
1 parent 3f86c78 commit 8700a27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/common/utils/stringHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,12 @@ export const safeJsonParse = (str) => {

// Converts JSON to a string and removes curly brackets, square brackets, and double quotes
export const convertJsonToReadableString = (json) => {
const message = JSON.stringify(json)
return message?.replace(/[{}[\]"]+/g, ' ') || ''
try {
const message = JSON.stringify(json)
return message?.replace(/[{}[\]"]+/g, ' ') || ''
} catch (e) {
return 'Error'
}
}

export const makeTypeSingular = (plural) => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/validationHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const definitions = {
yup.object({
text: stringWithMax(charCount).min(
1,
'This field cannot be empty. Remove it if you do not want to inlcude it.',
'This field cannot be empty. Remove it if you do not want to include it.',
),
}),
),
Expand Down
4 changes: 3 additions & 1 deletion src/components/Form/TextArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function TextArrayField({
</div>
{errors?.[nameId]?.[index] && (
<div className="text-red-500">
{convertJsonToReadableString(errors?.[nameId]?.[index])}
{convertJsonToReadableString(
errors?.[nameId]?.[index]?.text?.message,
)}
</div>
)}
</li>
Expand Down

0 comments on commit 8700a27

Please sign in to comment.