Hi
I have a formpanel which has only one text field. I have added few validations via setValidator() method. I am calling textfield.validate() method on click of submit button. But validator.validate method is being called only if we do some edit in the textfield. On page load if we directly click submit button validator.validate() method is not being called. So validation is success always even if we dont have proper value. Below is the test case
Code:
public void onModuleLoad() {
FormPanel formPanel = new FormPanel();
formPanel.setHeading("Test form");
final TextField<String> field = new TextField<String>();
field.setFieldLabel("Test");
field.setTitle("Test");
field.setValidateOnBlur(true);
//field.setAllowBlank(false); //I dont want to set this upfront
field.setMinLength(1);
field.setValidator(new Validator() {
@Override
public String validate(Field<?> field, String value) {
boolean allowBlankValue = false;//this will be set based on some condition at runtime
if (!allowBlankValue && (value == null || value.trim().length() < 1)) {
return "Enter valid value";
}
if (!value.trim().equalsIgnoreCase("test")) {
return "Text not matching";
}
return null;
}
});
formPanel.add(field);
Button submitButton = new Button("Submit");
submitButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
if (field.validate()) {
Window.alert("success");
}
}
});
formPanel.addButton(submitButton);
RootPanel.get().add(formPanel);
}
Am I missing anything here or is this the issue? Thanks in advance.
GXT Version : 2.2.3
GWT Version : 2.2.0