SmartGWT 3.0
FF 3.6
I have a custom server side validator which returns false when validation errors exist. Furthermore, the client displays the validation error with the correct error message. This is all good.
The part I'm having trouble with is ValuesManager.hasErrors() seems to return false, even when there are validation errors being displayed to the user. This seems to only be true when the validator type="custom". With type="integerRange" hasErrors() will display true. See test case below.
Client code, Test.java
testDS.ds.xml that returns false for hasErrors() (i.e. the custom validator):
The NumberValidator:
When I don't use the custom validator and use this testDS.ds.xml instead, all is well:
Steps to recreate (using testDS.ds.xml with custom validator):
1) Load client
2) Enter 200 in the text item.
3) navigate away from the form item and wait for validation to return
4) Click submit and observe hasErrors() has returned false
Steps to recreate (using testDS.ds.xml with integerRange validator):
1) Load client
2) Enter 200 in the text item.
3) navigate away from the form item and wait for validation to return
4) Click submit and observe hasErrors() has returned true
FF 3.6
I have a custom server side validator which returns false when validation errors exist. Furthermore, the client displays the validation error with the correct error message. This is all good.
The part I'm having trouble with is ValuesManager.hasErrors() seems to return false, even when there are validation errors being displayed to the user. This seems to only be true when the validator type="custom". With type="integerRange" hasErrors() will display true. See test case below.
Client code, Test.java
Code:
import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.ValuesManager; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.events.ClickEvent; import com.smartgwt.client.widgets.form.fields.events.ClickHandler; public class Test implements EntryPoint { @Override public void onModuleLoad() { DataSource dataSource = DataSource.get("testDS"); final ValuesManager valuesManager = new ValuesManager(); DynamicForm form = new DynamicForm(); form.setDataSource(dataSource); form.setValuesManager(valuesManager); valuesManager.addMember(form); valuesManager.setDataSource(dataSource); TextItem number = new TextItem("number", "Number"); number.setValidateOnExit(true); ButtonItem submit = new ButtonItem("submit", "Submit"); submit.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { valuesManager.validate(); boolean hasErrors = valuesManager.hasErrors(); SC.say("Has errors: "+hasErrors); } }); form.setFields(number, submit); form.draw(); } }
Code:
<DataSource ID="testDS"> <fields> <field name="number" type="integer"> <validators> <validator type="serverCustom"> <serverObject lookupStyle="new" className="NumberValidatorDMI"/> <errorMessage>Valid range is 0 - 49, 51-100.</errorMessage> </validator> </validators> </field> </fields> </DataSource>
Code:
import java.util.Map; import com.isomorphic.datasource.DataSource; import com.isomorphic.datasource.Validator; public class NumberValidatorDMI { public boolean condition(Object value, Validator validator, String fieldName, Map record, DataSource ds) throws Exception { if (value == null) { return false; } int number = Integer.parseInt(value.toString()); if (number == 50 || number < 0 || number > 100) { return false; } return true; } }
Code:
<DataSource ID="testDS"> <fields> <field name="number" type="integer"> <validators> <validator type="integerRange" max="100" min="0" errorMessage="Valid range of values is 0-100"/> </validators> </field> </fields> </DataSource>
1) Load client
2) Enter 200 in the text item.
3) navigate away from the form item and wait for validation to return
4) Click submit and observe hasErrors() has returned false
Steps to recreate (using testDS.ds.xml with integerRange validator):
1) Load client
2) Enter 200 in the text item.
3) navigate away from the form item and wait for validation to return
4) Click submit and observe hasErrors() has returned true
Comment