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

fix: add validation for myinfo child name field #7875

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

kevin9foong
Copy link
Contributor

@kevin9foong kevin9foong commented Nov 11, 2024

Continuation of PR 7874

Tests

myinfo child fields are properly validated as required by the FE.

  • Create a myinfo child field with all subfields
  • Submit the form and leave it empty, ensure that the required FE validation error message is shown for all fields
  • select a child which does prefill -> ensure that the prefilled fields no longer have an error
  • submit and notice that secondary race which is not prefilled still has a required error
  • fill it up and submit -> ensure that it works fine

@kevin9foong kevin9foong requested a review from KenLSM November 11, 2024 06:43
@kevin9foong kevin9foong self-assigned this Nov 11, 2024
@@ -322,33 +315,28 @@ const ChildrenBody = ({
<FormLabel gridArea="formlabel">Child</FormLabel>
<Flex align="stretch" alignItems="stretch" justify="space-between">
<Box flexGrow={10}>
<FormControl key={field.id} isRequired isInvalid={!!childNameError}>
<FormControl key={field.id} isRequired isInvalid={!!error?.[0]}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Sudden use of hardcoded index access (i.e., [0]) looks suspicious. Should it be the index of the current child instead?

i.e., Child Component has two rows, the validation error is on 2nd child instead, would this error?.[0] pick up the error on the correct child?

Copy link
Contributor Author

@kevin9foong kevin9foong Nov 11, 2024

Choose a reason for hiding this comment

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

hi ken, seems like the hardcoding of the index where 0th element refers to the name field is a deterministic behaviour since a while ago. (see attached ss)

image

exploring further, the index of the error message is fixed. if an error does not exist, then it will be an empty element. for eg, this screenshot shows a case when only the 5th field has an error and the others do not - the rest of the fields still keep the same index but are empty.
image

hence, the above Child Component has two rows, the validation error is on 2nd child instead, would this error?.[0] pick up the error on the correct child? is guaranteed to not occur

was considering adding a const NAME_INDEX = 0 and using it but not sure if it will add more clarity

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think const NAME_INDEX = 0 gives it more clarity, since I was also confused why it is always the first index. Explicitly calling it out makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ill add it in then

@kevin9foong kevin9foong merged commit b23dce1 into develop Nov 11, 2024
18 checks passed
@kevin9foong kevin9foong deleted the fix/child-field-missing-validation branch November 11, 2024 07:30
@kevin9foong kevin9foong mentioned this pull request Nov 13, 2024
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants