shaab01
20 Nov 2009, 4:31 AM
I have a form with couples of TextFields with setAllowBlank(false) . Now when this form is loaded it marks these TextFileds Invalid, Which I do not want as it looks bad. Idealy when the user clicks at these fields an leave them blank, then only the fields should be marked "Invalid" and this is the Expected behavior. I get this expected behavior but the problem is when I have Field binding on these fields. Without binding, it works fine, but with binding, the fields are initialized with the Model object and fields are marked invalid.
Can any one help me to make sure the fields are not marked invalid at loading, even if I use Bindings on the fields.
Here is code :
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.widget.ContentPanel;
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.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
/**
*
* @author shaab01
*/
public class MainEntryPoint implements EntryPoint {
private BaseModel computerData;
/** Creates a new instance of MainEntryPoint */
public MainEntryPoint() {
}
/**
* The entry point method, called automatically by loading a module
* that declares an implementing class as an entry-point
*/
public void onModuleLoad() {
final ContentPanel cp = new ContentPanel();
cp.setSize("500", "500");
computerData = new BaseModel();
cp.add(createNetworkIdentificationForm());
cp.layout();
RootPanel.get().add(cp);
}
private FormPanel createNetworkIdentificationForm() {
FormData formData = new FormData("");
FormPanel form2 = new FormPanel();
FormBinding binding = new FormBinding(form2);
binding.bind(computerData);
form2.setHeaderVisible(false);
form2.setLayout(new FormLayout());
FormLayout layout = new FormLayout();
layout.setLabelWidth(120);
TextField<String> hostName = new TextField<String>();
hostName.setName("HostName");
hostName.setFieldLabel("Host Name*");
hostName.setAllowBlank(false);
TextField<String> macAddress = new TextField<String>();
macAddress.setName("macAddress");
macAddress.setFieldLabel("Mac Address*");
macAddress.setAllowBlank(false);
form2.add(hostName, formData);
form2.add(macAddress, formData);
// manually add bindings
binding.addFieldBinding(new FieldBinding(hostName, "hostName"));
binding.addFieldBinding(new FieldBinding(macAddress, "macAddress"));
hostName.clearInvalid();
//hostName.setValue(null);
return form2;
}
}
Can any one help me to make sure the fields are not marked invalid at loading, even if I use Bindings on the fields.
Here is code :
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.widget.ContentPanel;
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.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
/**
*
* @author shaab01
*/
public class MainEntryPoint implements EntryPoint {
private BaseModel computerData;
/** Creates a new instance of MainEntryPoint */
public MainEntryPoint() {
}
/**
* The entry point method, called automatically by loading a module
* that declares an implementing class as an entry-point
*/
public void onModuleLoad() {
final ContentPanel cp = new ContentPanel();
cp.setSize("500", "500");
computerData = new BaseModel();
cp.add(createNetworkIdentificationForm());
cp.layout();
RootPanel.get().add(cp);
}
private FormPanel createNetworkIdentificationForm() {
FormData formData = new FormData("");
FormPanel form2 = new FormPanel();
FormBinding binding = new FormBinding(form2);
binding.bind(computerData);
form2.setHeaderVisible(false);
form2.setLayout(new FormLayout());
FormLayout layout = new FormLayout();
layout.setLabelWidth(120);
TextField<String> hostName = new TextField<String>();
hostName.setName("HostName");
hostName.setFieldLabel("Host Name*");
hostName.setAllowBlank(false);
TextField<String> macAddress = new TextField<String>();
macAddress.setName("macAddress");
macAddress.setFieldLabel("Mac Address*");
macAddress.setAllowBlank(false);
form2.add(hostName, formData);
form2.add(macAddress, formData);
// manually add bindings
binding.addFieldBinding(new FieldBinding(hostName, "hostName"));
binding.addFieldBinding(new FieldBinding(macAddress, "macAddress"));
hostName.clearInvalid();
//hostName.setValue(null);
return form2;
}
}