sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.29k stars 1.06k forks source link

How to bind NumberValidator with button.disableProperty()? #1098

Closed Swapnil722Git closed 3 years ago

Swapnil722Git commented 4 years ago

I want to bind NumberValidator with button.disableProperty();

public class NewController {
   @FXML
    private JFXButton saveButton;

   @FXML
    private JFXTextField numJFXTextField;

    NumberValidator num = new NumberValidator();

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        saveButton.disableProperty().bind(Bindings.isNotEmpty(num.messageProperty())); 

        digitValidator(numJFXTextField, num);
}

    public void digitValidator(JFXTextField jFXTextField, NumberValidator numberValidator) {
        jFXTextField.getValidators().add(numberValidator);
        numberValidator.setMessage("Only numbers are allowed.");
        jFXTextField.setOnKeyTyped((KeyEvent event) -> {
            jFXTextField.validate();
        });
    }
}

I know it wouldn't work since messageProperty is hard-coded and never be empty. So which property I should use to accomplish this?

qtran commented 4 years ago

What about the NumberValidator.hasErrorsProperty() ?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.