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

Improve error message accessibility in registration form #6324

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

foxbunny
Copy link
Collaborator

@foxbunny foxbunny commented May 7, 2024

  • Add FormErrors component that lists fields with errors
  • Add selector to obtain a flat field list
  • Add message-box component to design system
  • Add id to PictureInput wrapper

- Add FormErrors component that lists fields with errors
- Add selector to obtain a flat field list
- Add message-box component to design system
- Add id to PictureInput wrapper <div>
Comment on lines 18 to 32
const formFieldList = useSelector(getFlatFieldList);
const fieldLabelLookup = useMemo(() => {
const lookup = new Map();
for (const formField of formFieldList) {
lookup.set(formField.htmlName, {
label: formField.title,
id: `input-${formField.id}`,
});
}
lookup.set('captcha', {
label: Translate.string('Captcha'),
id: 'input-captcha',
});
return lookup;
}, [formFieldList]);
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer putting this logic in a selector:

export const getFieldLabelMapping = createSelector(
  getItems,
  fields => {
    const mapping = new Map();
    Object.values(fields).forEach(formField => {
      mapping.set(formField.htmlName, {
        label: formField.title,
        id: `input-${formField.id}`,
      });
    });
    mapping.set('captcha', {
      label: Translate.string('Captcha'),
      id: 'input-captcha',
    });
    return mapping;
  }
);

(code untested)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. Will take care of that tomorrow.

continue;
}

fieldsWithErrors.push({label: field.label, id: field.id, message: errors[fieldName]});
Copy link
Member

Choose a reason for hiding this comment

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

Could be simplified to {...field, message: errors[fieldName]} since you use everything from field anyway.

@@ -170,7 +172,7 @@ export default function RegistrationFormSubmission() {
onSubmit={onSubmit}
initialValues={isUpdateMode ? registrationData : initialValues}
initialValuesEqual={_.isEqual}
subscription={{}}
subscription={{errors: true}}
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that's needed? I think if you use useFormState in your component you can specify the subscription in there in order to just re-render your component instead of the whole form here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to FormSpy which subscribes to errors.

Copy link
Member

Choose a reason for hiding this comment

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

You can revert the change to this line then, since the component where you added the useFormState will automatically re-render and it should no longer be necessary to re-render here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm, I thought I have. Guess not. 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

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.

None yet

3 participants