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

[EuiFieldText] required prop validating immediately, not on blur #4710

Closed
j-m opened this issue Apr 14, 2021 · 5 comments
Closed

[EuiFieldText] required prop validating immediately, not on blur #4710

j-m opened this issue Apr 14, 2021 · 5 comments

Comments

@j-m
Copy link
Contributor

j-m commented Apr 14, 2021

The required prop is violating the form usage guidelines

Validate on blur
Validation should occur on blur from an input field. The submit button should be active by default, then show errors after click. Error messages should be specific to the situation.

Here's a fork of the form validation sandbox

@j-m
Copy link
Contributor Author

j-m commented Apr 14, 2021

Appears to just be a styling issue, resolved with

.euiFieldText:not(:focus):invalid {
  background-image: none;
}
.euiFieldText:not(:placeholder-shown):invalid {
  background-image: linear-gradient(to top, #bd271e, #bd271e 2px, transparent 2px, transparent 100%);
}

Essentially just replacing

.euiFieldText:invalid {
    background-image: linear-gradient(to top, #BD271E, #BD271E 2px, transparent 2px, transparent 100%);
    background-size: 100%;
}

with

.euiFieldText:not(:placeholder-shown):invalid {
    background-image: linear-gradient(to top, #BD271E, #BD271E 2px, transparent 2px, transparent 100%);
    background-size: 100%;
}

@cchaos
Copy link
Contributor

cchaos commented Apr 14, 2021

Yes, we intentionally override the invalid color with the focus color when the input is in focus. If validation only occurs onBlur then the invalid marker would continue to be present even if they've changed their input to be valid.

Appreciate the feedback here, but not something we will be changing as it was a conscious decision.

@cchaos cchaos closed this as completed Apr 14, 2021
@j-m
Copy link
Contributor Author

j-m commented Apr 14, 2021

Apologies, the fork link was supposed to take you to a codepen.

Ignore focus, that was needed so my patch would work.
You'll see in the codepen that the first and second fields are invalid; all I've done is add the required prop to them.

@j-m
Copy link
Contributor Author

j-m commented Jun 15, 2021

@cchaos Reading your comments back, I think there was a misunderstanding here and believe this issue should be reopened.

To elaborate, if a field is required then EUI will immediately show it as invalid, even if the user hasn't attempted to enter anything.

@cchaos
Copy link
Contributor

cchaos commented Jul 19, 2021

Unfortunately that's just how browser's interpret required on empty inputs. Here's a blank codepen showing the basic implementation: https://codepen.io/clhorn99/pen/bGBdbaV

And an explanation from MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required#constraint_validation

Screen Shot 2021-07-19 at 14 27 36 PM

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

No branches or pull requests

2 participants