Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

a11y: use onGetErrorMessage in createDialogModal#2345

Closed
beyackle wants to merge 5 commits intomasterfrom
beyackle/newDialogErrorMsg
Closed

a11y: use onGetErrorMessage in createDialogModal#2345
beyackle wants to merge 5 commits intomasterfrom
beyackle/newDialogErrorMsg

Conversation

@beyackle
Copy link
Contributor

@beyackle beyackle commented Mar 23, 2020

Description

This reworks createDialogModal.tsx a bit by moving the error checking into the Fabric-supported "onGetErrorMessage" and using a boolean in the modal's state to keep track of if we see any errors.

Task Item

Closes #2074
Closes #2060

Screenshots

image

@github-actions
Copy link

Coverage Status

Coverage increased (+0.009%) to 39.369% when pulling 287fbcb on beyackle/newDialogErrorMsg into 5e6a9e9 on master.

Copy link
Contributor

@a-b-r-o-w-n a-b-r-o-w-n left a comment

Choose a reason for hiding this comment

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

Can we just move the validation to the onChange handler? In fact, there is another PR (#2338) that is the same issue but solved differently. I think this warrants a custom hook, like useForm. I can see an interface like:

interface FormField {
  name: string;
  /** pass formData in order to validate under certain conditions */
  onValidate: (data: any, formData: any) => string | undefined;
}

interface FormState {
  formData: { [key: string]: any };
  formErrors: { [key: string]: any };
  onChange: (field: string) => (value: any) => void;
}

type useForm = (fields: FormField[]) => FormState;

This way we can unify our form behavior.

cc @liweitian


const _onGetErrorMessage = (name: string) => {
if (name) {
if (!nameRegex.test(name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is used before its defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's defined on line 46 and used on line 88. I don't see the issue.

@a-b-r-o-w-n
Copy link
Contributor

This is actually addressing the same issue as #2338. So we may not need to overcomplicate with a hook, but if we want a consistent behavior for other forms, it seems worth the investment to me.

@beyackle
Copy link
Contributor Author

Can we just move the validation to the onChange handler?

That was the first thing I tried, and it didn't do the validation when I expected it should. This way, we're using the supported method from Fabric's own API documentation.

@a-b-r-o-w-n
Copy link
Contributor

Closing in favor of #2369

@a-b-r-o-w-n a-b-r-o-w-n deleted the beyackle/newDialogErrorMsg branch March 26, 2020 00:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants