CrossField validation is checking several attributes, by this reason we could not unambiguously which field should be highlighted in red.
But StandardEditor screen has validateAdditionalRules() method. You can override this method for your entity screen editor and add some logic and validation errors indicating the component (field).
I tried to do the validateAdditionalRules method, but although I would be able to validate what I need it still doesn’t highlight the field I associate the validation error with:
My solution in the end was as follows (Thank you Andrey B.)
@Install(to = "endDateField", subject = "validator")
private void endDateFieldValidator(LocalDate fieldValue) {
boolean valid = false;
if(getEditedEntity().getUsertype() == HrUserType.INTERNAL){
valid = true;
} else if (getEditedEntity().getEndDate() == null){
valid = false;
} else {
Integer maxPeriodForExternalStaff = 549;
LocalDate today = LocalDate.now();
LocalDate maxDate = today.plusDays(maxPeriodForExternalStaff);
valid = fieldValue.isBefore(maxDate);
}
if (!valid) {
throw new ValidationException("The end date can be no later than 18 months after today's date.");
}
}
You may have to look into the validateAdditionalRules as it doesn’t seem to highlight fields, at least not Date fields, I didn’t test other field types.