Hi all, I am having difficulties in performing val...
# tornadofx
b
Hi all, I am having difficulties in performing validation. I will like the validation error to appear once I click on the submit button.
b
Hi @FRQDO, I have been there but can not have it work. I do not want to disable the button
f
So, let me recap to make sure I get what you’re trying to build: • You have a form that a users enters data into. • At some point, the user submits the data. • If the data is erroneous, an error should be shown instead of the data being sent. • The error should only be shown after the button was clicked (that is, the user doesn’t know he made a mistake until the very end)
b
perfect
f
Do you want a generic error message or would you like to highlight the bad input fields when the button is clicked?
b
generic error
even a highlight will do. Need something that will catch the user attention
f
So, my first idea would be that you take the submit button’s action closure, check the model for validity, and then choose: either enable an error indicator of some sorts or submit the (valid) model
Why don’t you want to catch the user’s attention earlier though?
b
how do I do that?
f
The closure? Something like
Copy code
button("Submit") {
        action {
            if(model.valid) {
                // submit
            } else {
                // show error
            }
        }
    }
b
thanks
f
But wouldn’t it be more convenient for your user if they saw their mistakes right away?
b
before hitting the button?
f
For instance, you enter an email address that has no
@
in it – why not highlight the field as soon as it loses focus (
onBlur
) instead of when the user clicks the submit button?
And additionally, when the submit button is disabled, the user knows that something must be wrong because he cannot do the obvious next step, so you definitely catch the user’s attention
(Not trying to talk you out of your way, just trying to understand why you prefer it)
b
ok thanks. I will go that way then.
ahahah
I sincere appreciate the help. I think I need to change the way I think a little.
😁
f
We all do, all the time. To live is to learn 😉
(That’s also why I asked – could be that your model can not be verified in some intermediate step, and then I’d be curious about the model you are working with)
b
Thank you very much @FRQDO
f
No problem, glad I can give back to the community
❤️ 1
e
Hang on. This is all supported, and AFAIK it's documented with examples. You can choose to have validators update on change for example. You can also bind your submit button to the valid state of your model, so you simply can't click it until you have valid input. There should be several examples of this in the guide 🙂
To be clear, you can also update decorators on change.
f
Yep, hence the link to that very tutorial