Make BindingBuilder.asRequired
use HasValue.isEmpty
#21106
Labels
BindingBuilder.asRequired
use HasValue.isEmpty
#21106
Describe your motivation
Currently
BindingBuilder.asRequired
creates a validator that compares the component's value against itsHasValue.getEmptyValue
. In some cases that is not useful, as a component might have multiple empty states. Consider theRichTextEditor.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
useHasValue.isEmpty
to test whether the field has a value or not. That would allow components to have a customHasValue.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 inasRequired
.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 ifHasValue.isEmpty
returns true, so that the validator is triggered. However that might also require overridingHasValue.clear
to not useHasValue.getEmptyValue
and instead use some constant value.Alternatively, users could create custom validators instead of relying on the default validator created by
asRequired
.The text was updated successfully, but these errors were encountered: