-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Add Input.error
property
#894
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally looked into your PR, @itay-raveh!
In order to use this feature across all input elements with validation (input, number, textarea), I refactored it into a mixin. This nicely separates the validation code from other concerns.
Regarding the change to validation
being an Optional[Dict]
rather than a possibly empty Dict
: I'm not quite convinced that we need this change. Therefore I switched back to a Dict
. But maybe there is an argument I missed.
And I'm thinking about whether the property name error
is to generic and should be something like validation_error
. Once we release a new feature with a certain name, it's always tricky to change it later.
Oh, there's another point we need to think about: How to integrate Maybe we simply add i = ui.number(min=0, max=100, value=50, validation={'Too small!': lambda value: value > 80})
...
if i.error or i.out_of_limits:
ui.notify('Something is wrong.') |
Added an
error
property to theInput
element which always contains the latest error message from the given validators.Motivation
Say we have the following
ui.input
setup:Say in the
on_submit
callback we want to base behavior on the error state.How would that look before and after this PR?
Checking if an error is active
Before
After
Checking if a specific error is active
Before
After