Reputation:
My application contains a part where the user inputs their name, email etc. but they can also add the date (it doesn't have an initial value)
The date is a DatePicker.
What I have done is added a binding to a "submit" button to make sure that the users have inputted all the information before the button becomes available, however, I don't know how to bind to the LocalDate.
I tried this method which works (except for the date.getValue() at the end):
public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty().or(txtSurname.textProperty().isEmpty()).or
(txtPNumber.textProperty().isEmpty()).or(txtEmail.textProperty().isEmpty()).or(date.getValue() == null);
}
the last part: .or(date.getValue() == null);
gives me an error which says
The method or(ObservableBooleanValue) in the type BooleanExpression is not applicable for the arguments (boolean)
I was wondering whether there was another way to bind the button to the LocalDate as well.
Thank you
Upvotes: 0
Views: 265
Reputation: 209418
Assuming date
is a DatePicker
, you can just use
date.valueProperty().isNull()
which returns a BooleanBinding
. I.e.:
public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty()
.or(txtSurname.textProperty().isEmpty())
.or(txtPNumber.textProperty().isEmpty())
.or(txtEmail.textProperty().isEmpty())
.or(date.valueProperty().isNull());
}
Upvotes: 2