I have two fields: username and password. I want a button to remain disabled if these fields are blank or their length is less and n characters.
I tried using button disableProperty()
in my controller but I want to do the validation in the FXML file. I don't know if it's possible or not.
My current validation:
@FXML
private TextField usernameField;
@FXML
private PasswordField passwordField;
@FXML
private Button signinButton;
// Runs on initializing
@Override
protected void configure() {
signinButton.disableProperty().bind(usernameField.textProperty().isEmpty()
.or(usernameField.textProperty().length().lessThan(5))
.or(passwordField.textProperty().isEmpty())
.or(passwordField.textProperty().length().lessThan(4)));
}
FXML file:
<TextField fx:id="usernameField" prefHeight="34.0" prefWidth="220.0" promptText="Username"/>
<PasswordField fx:id="passwordField" prefHeight="34.0" prefWidth="220.0" promptText="Password"/>
<Button fx:id="signinButton" mnemonicParsing="false" onAction="#onSignin" prefWidth="220.0" text="Sign in"/>
Thanks in advance!