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

[Enhancement Request] [DatePicker] Chance to decide the event for showing hidding validation #1336

Open
Ginxo opened this issue Sep 5, 2024 · 0 comments

Comments

@Ginxo
Copy link

Ginxo commented Sep 5, 2024

Since errors from DatePicker validations are just shown after bluring:

I would like to have the way for showing the validation errors during onTextInput event. For now I'm work-arounding this by

  const [value, setValue] = useState(initialValue);
  const [invalidDateError, setInvalidateError] = useState<string>();
  // Not to duplicate error messages and display error during onChange
  const [showInvalidDateError, setShowInvalidDateError] = useState(true);
  const dateValidators = ...

  return (
    <>
      <DatePicker
        onChange={(_, dateStr) => {
          setValue(dateStr);
          setShowInvalidDateError(true); // To show errors during typing
        }}
        onBlur={(_, dateStr) => {
          setValue(dateStr);
          setShowInvalidDateError(false); // To not duplicate errors coming either from invalidDateError and the ones from the component
        }}
        value={value}
        validators={dateValidators}
      />
      {invalidDateError && showInvalidDateError ? (
        <HelperText>
          <HelperTextItem variant="error">{invalidDateError}</HelperTextItem>
        </HelperText>
      ) : undefined}
    </>
  );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs triage
Development

No branches or pull requests

1 participant