Empty TextField not validating?

Hi.

Why validator isn’t called on empty TextField?

Se following example ( I need to have 2-4 char long string ):


        Window w = new Window("");
        TextField field = new TextField();
        field.addValidator(new StringLengthValidator("err", 2, 4, true)); // string 2-4 chars
       
        Button button = new Button();
        button.addListener(new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
              print( field.isValid() );
            }
        });

        w.addComponent(label);
        w.addComponent(field);
        w.addComponent(button);

        setMainWindow(w);

When textfield is empty, validator is never called when calling isValid().

Is this right or it is a bug? I think it would be called…


thx
Dusan

Calling field.setRequired(true) will result in a “validation” error e.g. if the field is empty and you try to commit it.

Currently, validators are not called for fields for which isEmpty() returns true, but only the “required” check is performed. This is somewhat limiting in some cases, but is not likely to change in the 6.x series to preserve backwards compatibility.