I want to do some validation in JavaFx using ControlsFX. my code is like this:
ValidationSupport support = new ValidationSupport();
boolean isValid = true;
if(textField.getText().trim().isEmpty()) isValid = false;
support.registerValidator(testField, Validator.createEmptyValidator("This field is required!"));
My question is if is it possible to omit the if condition and extract whether or not the textField is empty from the validation support
Your
isValidvariable and theifstatement aren't really doing anything. TheValidationSupportcontains an observableinvalidproperty with which you can register listeners:or (perhaps more conveniently) register bindings:
This last code snippet will ensure the
okButtonis only enabled if the text field is not empty.