Threaded View

  1. #1
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572
    Vote Rating
    3
    gslender is on a distinguished road

      0  

    Default [CLOSED] B5 - validator returns isvalid ??

    [CLOSED] B5 - validator returns isvalid ??


    Howdy...

    When calling isValid against a FormPanel, any fields with a custom validator are not checked correctly.

    The snippet below shows problem...

    1) Enter values for all but last field (password2 - which has the custom validator)

    2) click check and it returns True suggesting all fields have been checked for isvalid - clearly password2 did not have its isvalid correctly called??

    Looking at the GXT source I think the overridden validateValue(..) method needs an extra condition to consider if the validator is used (as it may be ok for the value length to be < 1)

    Perhaps consider moving the validator check to the top as if one is set, the other validators are kinda not needed (true?) - maybe add docs to say "if you set a validator, it will be called before all other set validations etc"

    Code:
    package com.mycompany.gxt.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    
    import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
    import com.extjs.gxt.ui.client.event.ComponentEvent;
    import com.extjs.gxt.ui.client.event.SelectionListener;
    import com.extjs.gxt.ui.client.widget.ContentPanel;
    import com.extjs.gxt.ui.client.widget.Info;
    import com.extjs.gxt.ui.client.widget.LayoutContainer;
    import com.extjs.gxt.ui.client.widget.Viewport;
    import com.extjs.gxt.ui.client.widget.button.Button;
    import com.extjs.gxt.ui.client.widget.form.FormPanel;
    import com.extjs.gxt.ui.client.widget.form.TextField;
    import com.extjs.gxt.ui.client.widget.form.Validator;
    import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
    import com.extjs.gxt.ui.client.widget.layout.CenterLayout;
    
    public class ValidatorTest implements EntryPoint {
    
        public void onModuleLoad() {
    
            ContentPanel cp = new ContentPanel();
            cp.setHeading("Test");
            cp.setSize(600, 400);
    
            LoginContainer lc = new LoginContainer();
            cp.add(lc);
    
            final Viewport vp = new Viewport();
            vp.add(cp);
            vp.layout();
    
            RootPanel.get().add(vp);
        }
    
        public class LoginContainer extends LayoutContainer {
            public LoginContainer() {
                super();
                setLayout(new CenterLayout());
    
                final FormPanel panel = new FormPanel();
                panel.setHeading("Validator test");
                panel.setFrame(true);
                panel.setFieldWidth(100);
                panel.setLabelWidth(80);
                panel.setLabelAlign(LabelAlign.RIGHT);
                panel.setButtonAlign(HorizontalAlignment.RIGHT);
                panel.setWidth(220);
    
                final TextField<String> userTxtFld = new TextField<String>();
                userTxtFld.setFieldLabel("Username");
                userTxtFld.setEmptyText("Username");
                userTxtFld.setAllowBlank(false);
                userTxtFld.setSelectOnFocus(true);
                panel.add(userTxtFld);
    
                final TextField<String> pwd1TxtFld = new TextField<String>();
                pwd1TxtFld.setPassword(true);
                pwd1TxtFld.setAllowBlank(false);
                pwd1TxtFld.setFieldLabel("Password1");
                panel.add(pwd1TxtFld);
    
                final TextField<String> pwd2TxtFld = new TextField<String>();
                pwd2TxtFld.setPassword(true);
                pwd2TxtFld.setFieldLabel("Password2");
                pwd2TxtFld.setValidator(new Validator<String, TextField<String>>() {
                    public String validate(TextField<String> field, String value) {
                        if (!value.equals(pwd1TxtFld.getValue())) return "Passwords do not match";
                        return null;
                    }
                });
                panel.add(pwd2TxtFld);
    
                final Button isvalidBtn = new Button("Check");
                panel.addButton(isvalidBtn);
    
                SelectionListener<ComponentEvent> listener = new SelectionListener<ComponentEvent>() {
                    public void componentSelected(ComponentEvent be) {
                        if (panel.isValid()) Info.display("isValid", "is true??");
                    }
                };
                isvalidBtn.addSelectionListener(listener);
    
                add(panel);
    
            }
        }
    }
    Last edited by gslender; 17 Jun 2008 at 5:20 PM. Reason: figured out a way to get a solution...