FieldGroup validation

I am building an application to monitor the inspection of packages. I have an attribute in my table “packaged inspected” which is a simple boolean. Before this can be switched to true, several other columns in the entity have to be filled. where would I implement the validator for this?

I’ve looked in the “Validator” section of the docs, and I understand how to validate a single field but I didn’t notice how to read the values from the other fields in the fieldgroup. How can I grab those fields and verify that they are filled?

Hi,

I can suggest you the following approach:

  • Add an ItemPropertyChangeListener
  • Change the boolean field enable or editable attribute according to whether the required fields are set

For example:

personDs.addItemPropertyChangeListener(e -> {
	if ("email".equals(e.getProperty()) || "phone".equals(e.getProperty())) {
		boolean hasContactInformation = getItem().getEmail() != null
			|| getItem().getPhone() != null;

		fieldGroup.getFieldNN("sendingMessages")
			.setEnabled(hasContactInformation);
	}
});

I’ve created a project that demonstrates the above at github.

Regards,
Gleb