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

Make BindingBuilder.asRequired use HasValue.isEmpty #21106

Open
sissbruecker opened this issue Mar 10, 2025 · 2 comments
Open

Make BindingBuilder.asRequired use HasValue.isEmpty #21106

sissbruecker opened this issue Mar 10, 2025 · 2 comments

Comments

@sissbruecker
Copy link
Contributor

Describe your motivation

Currently BindingBuilder.asRequired creates a validator that compares the component's value against its HasValue.getEmptyValue. In some cases that is not useful, as a component might have multiple empty states. Consider the RichTextEditor.isEmpty implementation for example, which not only checks whether the value is an empty string, but also whether there are only empty HTML tags.

Describe the solution you'd like

Make BindingBuilder.asRequired use HasValue.isEmpty to test whether the field has a value or not. That would allow components to have a custom HasValue.isEmpty implementation which would be respected by the validator.

At least at the moment, it looks like the respective default implementations of isEmpty do the same as the validator created in asRequired.

Describe alternatives you've considered

A hacky workaround to make this work in a component would be to customize HasValue.getEmptyValue to return the actual component value if HasValue.isEmpty returns true, so that the validator is triggered. However that might also require overriding HasValue.clear to not use HasValue.getEmptyValue and instead use some constant value.

Alternatively, users could create custom validators instead of relying on the default validator created by asRequired.

@knoobie
Copy link
Contributor

knoobie commented Mar 10, 2025

Might be related to #19847

@TatuLund
Copy link
Contributor

A hacky workaround to make this work in a component would be to customize HasValue.getEmptyValue to return the actual component value if HasValue.isEmpty returns true, so that the validator is triggered.

Example of that workaround can be found here:

https://gist.github.com/TatuLund/e4a66e42a00cb0e4173d770ee5f870e8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants