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

[SelectField] An empty and required select field stays valid #1087

Open
daniel-rodrigue opened this issue Mar 10, 2021 · 0 comments
Open

[SelectField] An empty and required select field stays valid #1087

daniel-rodrigue opened this issue Mar 10, 2021 · 0 comments
Labels
Milestone

Comments

@daniel-rodrigue
Copy link

daniel-rodrigue commented Mar 10, 2021

Description:

In order to quickly validate if a form is valid, I use the form's checkValidity() function. The browser will go through all the form's elements and check for their validity. This works well for most of the field components except for a required SelectField component. An empty SelectField with a required property and an empty value is seen as valid.

NOTE: this is with v1 (I didn't try with v2 since we are not ready to move to v2 yet).

To Reproduce:

// constructor:
this.ref = React.createRef();

...
// render:
<form ref={this.ref}>
  <SelectField id="some_id" label="some_label" menuItems={choices} required value="" />
</form>

And later on...

if ( this.ref.current.checkValidity() ) {
  // valid
} else {
  // not valid and report error..
}

Expected behavior:

Should report the select field as invalid because it's required and empty.

Desktop:

  • OS: [macOS Catalina]
  • Browser [Chrome]
  • Version [89.0.4389.82]

Additional info:

After debugging the code, I realized that the hidden input field (in SelectFieldInput) used to maintain the value is not mark as required. After testing that, the form's checkValidity still reports it as valid because it's a type hidden. Changing manually the type to a text field with a display:none style did the trick.

So it seems the fixes are:

  1. SelectFieldToggle should pass the required property to SelectInputField.
  2. SelectInputField should use a text form field, with the required attribute set and a style with display:none (likely also an aria-hidden is needed here).
@mlaursen mlaursen added the v1 label Mar 20, 2021
@mlaursen mlaursen added this to the v5.0.0 milestone Nov 24, 2021
@mlaursen mlaursen modified the milestones: v5.0.0, v6.0.0 Jan 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants