I need to validate simple JavaFX form with password and password confirmation.
validationSupport.registerValidator(passwordInput,
Validator.createEmptyValidator("Password required!"));
validationSupport.registerValidator(confirmPasswordInput,
new EqualsToValidator(passwordInput.textProperty(),
"Password differs from confirmation"));
In EqualsToValidator I simply compare property.getValue()
and value
passed to validator.
If I change only password EqualsToValidator
is not called because it is listening to confirmPasswordInput
not passwordInput
.
I have only found ugly solution:
passwordInput.textProperty().addListener((observable, oldValue, newValue) -> {
String oldText = confirmPasswordInput.getText();
confirmPasswordInput.setText(null);
confirmPasswordInput.setText(oldText);
});
How to invalidate one field when another field changes?