PDA

View Full Version : [FIXED] B5 - multifield validator bugs



gslender
14 Jun 2008, 5:04 PM
Few things wrong with multifield custom validator...

1) Implementation is messy and no real value can be obtained from validate() method (refactoring or passing of some value should be done to make sense of the generics used)

2) Even when working, no field value changes are correcting the isvalid status for the field - seems some notification for value change needs to fire a isvalid check to remove valid cross circle flag...

code below can be used to show problems...


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.CheckBox;
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
import com.extjs.gxt.ui.client.widget.form.Field;
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 MultiFieldValidatorTest 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(250);

final TextField<String> userTxtFld = new TextField<String>();
userTxtFld.setFieldLabel("Username");
userTxtFld.setEmptyText("Username");
userTxtFld.setAllowBlank(false);
userTxtFld.setSelectOnFocus(true);
panel.add(userTxtFld);

final CheckBoxGroup accepttermsChkBoxGrp = new CheckBoxGroup();
accepttermsChkBoxGrp.setFieldLabel("Agreement");
accepttermsChkBoxGrp.setValidator(new Validator<Boolean, Field<Boolean>>() {
public String validate(Field<Boolean> field, String value) {
if (new Boolean(accepttermsChkBoxGrp.get(0).getRawValue())) return null;
return "You must agree ";
}
});
CheckBox accepttermsChkBox = new CheckBox();
accepttermsChkBox.setBoxLabel("I accept");
accepttermsChkBoxGrp.add(accepttermsChkBox);
panel.add(accepttermsChkBoxGrp);

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);

}
}
}

gslender
20 Jun 2008, 2:34 PM
bump

darrellmeyer
27 Jun 2008, 6:43 AM
1) Implementation is messy and no real value can be obtained from validate() method (refactoring or passing of some value should be done to make sense of the generics used)
The multi field itself is passed to the validate method.


2) Even when working, no field value changes are correcting the isvalid status for the field - seems some notification for value change needs to fire a isvalid check to remove valid cross circle flag...
This is fixed.

gslender
27 Jun 2008, 1:25 PM
Thanks Darrell