I'm creating an application using Javafx in which in which I'm creating two different GridPanes say GridPane A and GridPane B. In GridPane A I've TextFields and GridPane B I've TextFields, Checkboxes and DatePickers, all the nodes I'm creating at run time. Under both of the GridPanes A and B I've a button like this:
What I want is to disable the button until both the entries of both GridPane A and GridPane B. I'm able on achieve it but only on GridPane A like this
First by checking if all the TextFields of GridPane A are filled and not empty:
private static boolean isAllFilled(GridPane tableA){
for(Node node : tableA.getChildren()){ // cycle through every component in the table (GridPane)
if(node instanceof TextField){ // if it's a TextField
// after removing the leading spaces, check if it's empty
if(((TextField)node).getText().trim().isEmpty()){
return false; // if so, return false
}
}
}
return true;
}
Then validating the TableA (GridPane A) and adding listener:
private void validateTable(GridPane tableA, Button button) {
for(Node node : tableA.getChildren()){ // cycle through every component in the table (GridPane)
if(node instanceof TextField){ // if it's a TextField
((TextField)node).textProperty().addListener((obs, old, newV)->{ // add a change listener to every TextField
// then check if the new value is not empty AND all other TextFields are not empty
if(!newV.trim().isEmpty()&&isAllFilled(tableA)){
button.setDisable(false); // then make the button active again
}
else{
button.setDisable(true); // or else, make it disable until it achieves the required condition
}
});
}
}
}
I want to apply validation simultaneously on both GridPane A and GridPane B, like right now my program is validating GridPane A entries and disabling/enabling the button but I want is to keep button disabled unless both GridPane A and GridPane B entries are filled.