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

what is the tornadofx way to have constraints for properties? #116

Open
ysm-coder opened this issue Jan 13, 2020 · 1 comment
Open

what is the tornadofx way to have constraints for properties? #116

ysm-coder opened this issue Jan 13, 2020 · 1 comment

Comments

@ysm-coder
Copy link

I couldnt find it in the guide, but bassicaly if I have some constraints (like String should only contain lowercase letters) I would check them in the setters and if something is wrong I can throw an Exception, display an Alert, return from the setter without setting anything or whatever. But in tornadofx I dont have var+setters but instead I have val properties like SimpleStringProperty. So what should I do? One idea is to somehow check this in .onChange{} but the problems I see with it is that this happens after the change (what if someone else also listens to the change and does something before I can check the constraint, also how do I get my old value back?). What is the intended way to do this?

@edvin
Copy link
Owner

edvin commented Jan 24, 2020

This is nicely solved in the validation support inside of the form builder. Please see Validation section of the guide, on this page: https://github.com/edvin/tornadofx-guide/blob/master/part1/11.%20Editing%20Models%20and%20Validation.md

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

No branches or pull requests

2 participants