Adding deregister/unregister to ValidationSupport

Issue #267 new
Hadi Fakhreddin
created an issue

Hi team,

Looking in ValidationSupport, there doesn't seem to be a way to remove a Control or a Validator after registering it with ValidationSupport.

Validator v = Validator.createEmptyValidator("control is required") validationSupport.registerValidator(control, v);

then It would be nice to be able to deregister using some of the following (whichever ones make sense): validationSupport.deregisterValidator(v) // deregister the validator or validationSupport.deregisterValidator(control) // deregister the control or validationSupport.deregisterValidator(control,v) // deregister the validator from control

I have a form that the validation rules for controls are set dynamically. For example doctor selection from drop down is mandatory unless "All Doctors" checkbox is selected. As a result I want to be able to deregister the validator for doctor dropdown when "All Doctors" is selected and register it again when the checkbox is deselected.

Comments (12)

  1. Eugene Ryzhikov

    You don't have to deregister. You can register custom Validator where, depending on value of your checkbox, you can do or skip the mandatory validation. For example of how to create custom Validator check the implementation of Validator.createEmptyValidator

  2. Hadi Fakhreddin reporter

    Thanks for the comment Eugene, I was hoping for a solution that limits the coupling of controls as opposed to making the controls aware of other controls' contents and state. I was aiming for having the parent node to keep track of what the validation state is.

  3. Hadi Fakhreddin reporter

    I added the validation so it's aware of the "allPractitioners" check box. This time instead of removing the validation, I am setting the practitioners as not required to remove the required/mandatory flag when not needed.

    ValidationSupport.setRequired(doctors, false);

    Interestingly it doesn't take effect once it's rendered!

    private ValidationSupport validationSupport = new ValidationSupport(); @FXML private ComboBox<Practitioner> practitioners; @FXML private CheckBox allPractitioners;

    public IncomeAccountingNode(){ validationSupport.registerValidator(practitioners, true, Validator.createEmptyValidator("Practitioner(s) is required")); // ValidationSupport.setRequired(practitioners, false); // this takes effect if uncommented

    allPractitioners.setOnAction((ActionEvent ae) -> {
        if (allPractitioners.isSelected()) {
            ValidationSupport.setRequired(practitioners, false);  //is not removing the mandatory flag
        } else {
            ValidationSupport.setRequired(practitioners, true);


    unfortunately I can't attach files, or I would include a screenshot. Should I raise a separate defect for this?

  4. Hadi Fakhreddin reporter

    Here is my work around for deRegistering the validator by registering a generic non-mandatory validator that always returns valid

    //Registering validationSupport.registerValidator(practitioners, Validator.createEmptyValidator("Practitioner(s) is required"));

    //deregistering validationSupport.registerValidator(practitioners, false, (Control c, Practitioner newValue) -> ValidationResult.fromErrorIf( c, "", false) );

  5. Eugene Ryzhikov

    "Deregistering" is something I have to look into. I think it makes sense to have such an API for dynamic cases like yours. The problem with required flag sounds like a bug, can you please file a separate issue?

  6. Andreas Liebelt

    Maybe my last suggestion in #250 is interesting for this issue too. It's an alternative API solution for "Deregistering".

    EDIT: PS: My suggestion is not really a deregistration, but a disabling of a registered validation. Maybe that does not match the original intention of this issue here.

  7. Alexandr

    Do we still have plans to add these features? It is really needed. I have a dynamic form, where controls can be added/removed while user works. Or perhaps there is some workaround for this case?

  8. Eva

    I would love to use this feature. Because it is missing now, I have to recreate ValidationSupport object to let old unattached forms to be garbage collected.

  9. Log in to comment