I am doing a basic validation for user input form, where I attached nameOfValidationLabel under each input. But these labels won't clear after the user correct the problem by adding the required text, so I added nameOfLable.setText(null) for each one of them at the beginning of the script. ok, that did the trick, but what happens if I have 20 or more validation labels.... is this the right way of doing it? Also, any clue on how to validate radio button section?
@FXML
private void handleButtonAction(ActionEvent event) throws IOException {
userIdLabel.setText(null);
passwordLabel.setText(null);
ipValueLabel.setText(null);
Stage stage;
Parent root;
if(event.getSource()==btn1){
if ((ipValue.getText().isEmpty() || ipValue.getText() == null)) {
ipValueLabel.setText("*IP address is required");
}
else if ((userId.getText().isEmpty() || userId.getText() == null)) {
userIdLabel.setText("*Enter Your UserID");
}
else if ((password.getText().isEmpty() || password.getText() == null)) {
passwordLabel.setText("*Enter Your Password");
}
else {
stage=new Stage();
root = FXMLLoader.load(getClass().getResource("Myfile.fxml"));
stage.setScene(new Scene(root));
stage.setTitle("Status Page");
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(btn1.getScene().getWindow());
stage.showAndWait();}
}
else {
stage=(Stage) btn2.getScene().getWindow();
stage.close();
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}