SmartGwt LGPL
6.1p
Latest Nightly 01/18/2018 09:02 +0000
Have a form with a ComboBoxItem.
ComboBoxItem filters its optionDataSource using setPickListFilterCriteriaFunction. The filter function filters all records from optionDataSource but one record, which is the shown in the list of the comboBoxItem.
ComboBoxItem also has IsOneOfValidator.
Now enter a value from optionDataSource, which is being filtered out by PickListFilterCriteriaFunction (i.e. the value entered is not part of the list of values of the comboBoxItem).
It is important, to actually type this value. In my test case below that value would be "testUser1".
Then perform form.validate.
Expected behaviour:
comboBoxItem does not validate.
Actual behaviour:
form.validate returns true.
What works though:
If a value is entered into comboBoxItem, which is not in optionDataSource (neither filtered or unfiltered), form.validate returns false as expected.
If the invalid value is set by code, e.g. "dynamicForm.setValue("someFieldName", "testUser1");", form.validate returns false as expected, too.
Could you please look into this?
TIA
André
Test Case:
6.1p
Latest Nightly 01/18/2018 09:02 +0000
Have a form with a ComboBoxItem.
ComboBoxItem filters its optionDataSource using setPickListFilterCriteriaFunction. The filter function filters all records from optionDataSource but one record, which is the shown in the list of the comboBoxItem.
ComboBoxItem also has IsOneOfValidator.
Now enter a value from optionDataSource, which is being filtered out by PickListFilterCriteriaFunction (i.e. the value entered is not part of the list of values of the comboBoxItem).
It is important, to actually type this value. In my test case below that value would be "testUser1".
Then perform form.validate.
Expected behaviour:
comboBoxItem does not validate.
Actual behaviour:
form.validate returns true.
What works though:
If a value is entered into comboBoxItem, which is not in optionDataSource (neither filtered or unfiltered), form.validate returns false as expected.
If the invalid value is set by code, e.g. "dynamicForm.setValue("someFieldName", "testUser1");", form.validate returns false as expected, too.
Could you please look into this?
TIA
André
Test Case:
Code:
package de.scai.smartgwttest.client.util; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.fields.DataSourceIntegerField; import com.smartgwt.client.data.fields.DataSourceTextField; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.ComboBoxItem; import com.smartgwt.client.widgets.form.fields.FormItemCriteriaFunction; import com.smartgwt.client.widgets.form.fields.FormItemFunctionContext; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; import de.scai.smartgwttest.client.Demo; import java.util.List; public class DemoTicket2045 implements Demo, EntryPoint { private Layout layoutRoot; /** * This is the entry point method. */ public void onModuleLoad() { layoutRoot = new VLayout(); RootPanel.get().add(layoutRoot); run(); } public DemoTicket2045(Layout layout) { super(); layoutRoot = layout; } private class UserDataSource extends DataSource { public static final String FIELDNAME_ID = "FIELD_id"; public static final String FIELDNAME_USERNAME = "FIELD_userName"; protected DataSourceIntegerField id = new DataSourceIntegerField(FIELDNAME_ID, "Id"); protected DataSourceTextField userName = new DataSourceTextField(FIELDNAME_USERNAME, "Username"); private UserDataSource() { super(); id.setPrimaryKey(true); addField(id); addField(userName); setClientOnly(true); setCacheAllData(true); createRecord(); } public void createRecord() { ListGridRecord listGridRecord = new ListGridRecord(); final ListGridRecord[] data = new ListGridRecord[2]; listGridRecord.setAttribute(FIELDNAME_ID, 1); listGridRecord.setAttribute(FIELDNAME_USERNAME, "testUser1"); data[0] = listGridRecord; listGridRecord = new ListGridRecord(); listGridRecord.setAttribute(FIELDNAME_ID, 2); listGridRecord.setAttribute(FIELDNAME_USERNAME, "testUser2"); data[1] = listGridRecord; setCacheData(data); } } private class SomeDynamicForm extends DynamicForm { protected ComboBoxItem comboBoxItem = new ComboBoxItem("someFieldName", "Lookup Field"); private UserDataSource userDataSource; protected void init() { userDataSource = new UserDataSource(); comboBoxItem.setOptionDataSource(userDataSource); comboBoxItem.setDisplayField(UserDataSource.FIELDNAME_USERNAME); comboBoxItem.setValueField(UserDataSource.FIELDNAME_ID); comboBoxItem.setValidators(new com.smartgwt.client.widgets.form.validator.IsOneOfValidator()); comboBoxItem.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction() { @Override public Criteria getCriteria(FormItemFunctionContext formItemFunctionContext) { java.util.List<com.smartgwt.client.data.Criterion> criterionList = new java.util.ArrayList<com.smartgwt.client.data.Criterion>(); criterionList.add( new com.smartgwt.client.data.Criterion( UserDataSource.FIELDNAME_USERNAME, com.smartgwt.client.types.OperatorId.EQUALS, "testUser2" ) ); return new com.smartgwt.client.data.AdvancedCriteria( com.smartgwt.client.types.OperatorId.OR, criterionList.toArray(new com.smartgwt.client.data.Criterion[criterionList.size()]) ); } }); this.setFields( comboBoxItem ); } } private SomeDynamicForm dynamicForm; public void run() { initForm(); Layout layout = new VLayout(); layoutRoot.addMember(layout); Label label = new Label("Type 'testUser1' into the comboxItem. It is not shown in the list of the " + "comboBoxItem, so validate should return false"); layout.addMember(label); layout.addMember(dynamicForm); Button buttonValidate = new Button("Validate"); buttonValidate.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { SC.say("Validate OK: " + Boolean.toString(dynamicForm.validate())); } }); layout.addMember(buttonValidate); } @Override public List<String> getRequiredEnvironmentInfo() { return null; } @Override public List<String> getFailedEnvironmentChecks() { return null; } private void initForm() { dynamicForm = new SomeDynamicForm(); dynamicForm.init(); } }
Comment