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

Overriding of ValidationResult for a nonParsableValue in DatePicker.checkValidity() not possible #4352

Closed
SonReimer opened this issue Dec 14, 2022 · 6 comments
Labels
enhancement New feature or request validation

Comments

@SonReimer
Copy link

SonReimer commented Dec 14, 2022

Description

I wanted to set an explicit error message to the ValidationResult.error(String) method in DatePicker.checkValidity(), but that is seems to be nearly not possible, because I had to overwrite the following methods:

  @Override
  public Validator<LocalDate> getDefaultValidator() {
      if (isFeatureFlagEnabled(FeatureFlags.ENFORCE_FIELD_VALIDATION)) {
          return (value, context) -> checkValidity(value);
      }

      return Validator.alwaysPass();
  }

  private ValidationResult checkValidity(LocalDate value) {
      if (isFeatureFlagEnabled(FeatureFlags.ENFORCE_FIELD_VALIDATION)) {
          boolean hasNonParsableValue = value == getEmptyValue()
                  && isInputValuePresent();
          if (hasNonParsableValue) {
              return ValidationResult.error(getResourceString("date.parse.error.message", getLabel()));
          }
      }

      var greaterThanMax = ValidationUtil.checkGreaterThanMax(value, getMax());
      if (greaterThanMax.isError()) {
          return greaterThanMax;
      }

      var smallerThanMin = ValidationUtil.checkSmallerThanMin(value, getMin());
      if (smallerThanMin.isError()) {
          return smallerThanMin;
      }

      return ValidationResult.ok();
  }
  
  @Synchronize(property = "_hasInputValue", value = "has-input-value-changed")
  private boolean isInputValuePresent() {
      return getElement().getProperty("_hasInputValue", false);
  }

I think setting the ValidationResult for hasNonParsableValue=true should be extracted to a protected method like

protected String getNonParsableValueErrorMessage() {
  return ""
}

Environment

Vaadin 23.3.0.beta2

@SonReimer
Copy link
Author

I think this issue may apply to other components like TimePicker DateTimePicker, BigDecimalField etc. as well.

@knoobie
Copy link
Contributor

knoobie commented Dec 14, 2022

Similar suggestion in the initial addition of the "feature": #3406 (comment)

@yuriy-fix yuriy-fix added enhancement New feature or request validation labels Dec 14, 2022
@yuriy-fix
Copy link
Contributor

The feature is not yet implemented, but we are currently investigating the ways of adding that one.

@SonReimer
Copy link
Author

What's the status of this issue ?

@SonReimer
Copy link
Author

Any idea, when this will be implemented ?

@vursen
Copy link
Contributor

vursen commented Jun 13, 2023

I'm closing the issue because we now have a dedicated ticket (#4618) specifically for the configuration of constraint error messages. Please, follow that ticket for further updates.

@vursen vursen closed this as completed Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request validation
Projects
None yet
Development

No branches or pull requests

4 participants