-
3 Aug 2008 6:23 PM #1
MultiField validation/allowBlank
MultiField validation/allowBlank
Hi,
In GXT 1.0.1 I'm using a MultiField to put first & last names on the same row and not allowing them to be blank. (see code example below). However formPanel.isValid() returns true even when firstNameText & lastNameText are blank. I suspect this is a bug...
MultiField nameField = new MultiField();
nameField.setFieldLabel("Full Name");
TextField firstNameText = new TextField();
nameField.add(firstNameText);
firstNameText.setEmptyText("First");
firstNameText.setAllowBlank(false);
formPanel.add(nameField);
TextField lastNameText = new TextField();
lastNameText.setFieldLabel("");
lastNameText.setEmptyText("Last");
lastNameText.setAllowBlank(false);
nameField.add(lastNameText);
-
3 Aug 2008 10:59 PM #2
there is a bug - a few in fact... (I've logged the bug too)
1) FormPanel.isValid() calls Field.isValid which calls validateValue(getRawValue()) - the problem is the getRawValue which when using empty text, results in text being in the field and so its evaluated as not being empty - which is clearly wrong.
Workaround is to not set an empty field - which works, but you get an incorrect msg.
2) Multifield displays the wrong invalid msg because of this code...
Code:// validate fields for (Field f : fields) { if (!f.validateValue(value)) { markInvalid("sdfdsffd"); /// <<<<<<<<<<<<<<< what the ???? return false; } }
-
5 Aug 2008 9:28 AM #3
I have changed the logic for validation with MultiField. I have also added a spacing option which is needed to display the error icon on the fields in a horizontal orientation. Changes are in SVN.
Code:public void onModuleLoad() { MultiField nameField = new MultiField(); nameField.setOrientation(Orientation.VERTICAL); nameField.setFieldLabel("Full Name"); nameField.setSpacing(5); TextField firstNameText = new TextField(); nameField.add(firstNameText); firstNameText.setEmptyText("First"); firstNameText.setAllowBlank(false); TextField lastNameText = new TextField(); lastNameText.setFieldLabel(""); lastNameText.setEmptyText("Last"); lastNameText.setAllowBlank(false); nameField.add(lastNameText); FormPanel formPanel = new FormPanel(); formPanel.add(nameField); RootPanel.get().add(formPanel); }


Reply With Quote