0

I have the following code

  public ValidationResult notNull(Control control, String content) {
        boolean condition = content.length() <=0;
        return ValidationResult.fromMessageIf(control, "Field is empty!", Severity.WARNING, condition);
    }

it checks if there is any character in text field,

the i call it like this

validator = new ValidationSupport();

validator.registerValidator(itemIdTf,vals::notNull);

and finally is do this

validator.invalidProperty().addListener((observable, oldValue, newValue) -> {
            itemIdTf.pseudoClassStateChanged(PseudoClass.getPseudoClass("negative"), oldValue);});

And this works, it sets the pseudo class for certain controll, how ever when i have few text field controls on same validatior it must wait for all of them to be validated before changing the pseudoclass.

so i thought to perhaps do it in the ValidationResult method, because i think using many validators is probably not good. How ever i dont know if that is possible, i need some listener that is unique to every control, not for validation result.

ImRaphael
  • 204
  • 3
  • 25

1 Answers1

0

well i found something that works, but it still leaves some unanswered questions :

  public ValidationResult notNull(Control control, String content) {



        boolean condition = content.length() <=0;

      control.pseudoClassStateChanged(positive,!condition);

        return ValidationResult.fromMessageIf(control, "Field is empty!", Severity.ERROR, condition);
    }

i am using css styling validator, so the things that come from this line do not work (at least not all of them)

return ValidationResult.fromMessageIf(control, "Field is empty!", Severity.ERROR, bp.getValue());

Here above there is string "Field is empty" which should be tooltip for control, however its never set, so i just created my own tooltip inside validation and i add it to control.

then the whole thing looks something like this :

PseudoClass positive = PseudoClass.getPseudoClass("positive");
    final Tooltip notNullTooltip = new Tooltip("Must have some value");
      public ValidationResult notNull(Control control, String content) {

            boolean condition = content.length() <=0;

          control.pseudoClassStateChanged(positive,!condition);
          control.setTooltip(notNullTooltip);
            return ValidationResult.fromMessageIf(control, "Field is empty!", Severity.ERROR, condition);
        }

And it does work, if anyone has more elegant solution i would be thankfull.

ImRaphael
  • 204
  • 3
  • 25