Modify invocation order of TextInput on_change and validation #2325
Labels
enhancement
New features, or improvements to existing features.
good first issue
Is this your first time contributing? This could be a good place to start!
Discussed in #2323
Via @cozimus
Originally posted by cozimus January 4, 2024
In this minimum working example I tried to enable/disable a button based on a
is_valid
condition on a TextInput:My goal is to disable the button whenever the text is not valid.
However when I modify the text with a non-number value, the button is still enabled, and it is disabled only when I change again the text.
It seems like the
on_change
handle is triggered before theis_valid
flag update, hence when I call myset_button
functions,is_valid
is still as the previous state.This should be the behavior of validation; the current behavior isn't intentional (or documented as such).
Suggested implementation
on_change()
and_validate()
calls used by every backend into a single (private)_value_changed()
method on the core class that can be invoked by backends whenever the value changes.on_change()
handler is invoked, theis_valid
status is correct. This validates that the core API provides utilities that validate in the correct order.on_change
to explicitly define that the field will have been validated when on_change is invoked.The text was updated successfully, but these errors were encountered: