Skip to content

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

Closed

Description

@j-m

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

Activity

  1. j-m commented on Apr 14, 2021

    @j-m
    ContributorAuthor

    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%;
    }
  2. cchaos commented on Apr 14, 2021

    @cchaos
    Contributor

    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.

  3. j-m commented on Apr 14, 2021

    @j-m
    ContributorAuthor

    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.

  4. j-m commented on Jun 15, 2021

    @j-m
    ContributorAuthor

    @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.

  5. cchaos commented on Jul 19, 2021

    @cchaos
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions