Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ValuesManager - validate() and getValues()

    SmartGWT 4.1 / FF 26

    If a value in a ValuesManager is changed, getValues() returns all the values including the changed value.

    But if you then call validate() followed by getValues(), all the values are returned but the changed value is back to its original value, even though the FormItem shows the updated value.

    #2
    We're taking a look at this - we'll let you know what we find / whether we need more information

    Regards
    Isomorphic Software

    Comment


      #3
      We'll need a way to reproduce this issue - it appears not to be a general problem with validation and ValuesManager.
      Here's a starter test case we built to check it out:
      Code:
      import java.util.HashMap;
      
      import com.google.gwt.core.client.EntryPoint;
      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.events.ClickEvent;
      import com.smartgwt.client.widgets.events.ClickHandler;
      import com.smartgwt.client.widgets.form.DynamicForm;
      import com.smartgwt.client.widgets.form.ValuesManager;
      import com.smartgwt.client.widgets.form.fields.TextItem;
      import com.smartgwt.client.widgets.form.validator.LengthRangeValidator;
      
      public class ValuesManagerTest implements EntryPoint {
      
      	@Override
      	public void onModuleLoad() {
      		
      		// Test DataSource. We won't actually fetch or save so no need for sample data etc.
      		DataSource testDS = new DataSource();
      		DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
      		pkField.setPrimaryKey(true);
      		pkField.setRequired(true);
      		
      		// Have a validator so we can test both validation success and failure
      		DataSourceTextField field0 = new DataSourceTextField("f0");
      		field0.setValidators(new LengthRangeValidator() {{
      			setMin(3);
      			setErrorMessage("Must be more'n 3 chars");
      		}});
      		DataSourceTextField field1 = new DataSourceTextField("f1");
      		DataSourceTextField field2 = new DataSourceTextField("f2");
      		DataSourceTextField field3 = new DataSourceTextField("f3");
      		
      		testDS.setFields(pkField, field0, field1, field2, field3);
      		
      		DynamicForm testForm0 = new DynamicForm();
      		testForm0.setDataSource(testDS);
      		testForm0.setFields(new TextItem("f0"), new TextItem("f1"));
      		testForm0.setLeft(10);
      		testForm0.setBackgroundColor("red");
      		
      		DynamicForm testForm1 = new DynamicForm();
      		testForm1.setDataSource(testDS);
      		testForm1.setFields(new TextItem("f2"), new TextItem("f3"));
      		testForm1.setLeft(300);
      		testForm1.setBackgroundColor("blue");
      		
      		final ValuesManager vm = new ValuesManager();
      		vm.setDataSource(testDS);
      		vm.addMember(testForm0);
      		vm.addMember(testForm1);
      		
      		// initial values
      		vm.setValues(new HashMap() {{
      			put("f0", "Initial zero");
      			put("f1", "Initial one");
      			put("f2", "Initial two");
      			put("f3", "Initial three");
      		}});
      		
      		
      		// Validation button
      		Button validator = new Button();
      		validator.setTitle("Validate");
      		validator.setTop(300);
      		validator.addClickHandler(new ClickHandler() {
      			
      			@Override
      			public void onClick(ClickEvent event) {
      				vm.validate();
      			}
      		});
      		Button showVals = new Button();
      		showVals.setTitle("Show Values");
      		showVals.setTop(350);
      		showVals.addClickHandler(new ClickHandler() {
      			
      			@Override
      			public void onClick(ClickEvent event) {
      				SC.logWarn("VM Values:" + vm.getValues());
      				SC.showConsole();
      			}
      		});
      		
      		testForm0.draw();
      		testForm1.draw();
      		validator.draw();
      		showVals.draw();
      				
      	}
      
      }
      What this does is creates 2 forms, bound to a dataSource, with a valuesManager to manage their values. There's a validator installed on field "f0" requiring 3 characters or more.
      If you click the button to "show values", the result of a 'getValues()' call is written into the developer console.

      If you edit the values (possibly setting "f0" to a string of just 2 chars such that it will not pass validation, and making other edits as well), then hit the "validate" button, then the "show values" button, the edited values appear to be showing up as expected.

      To show us a way to reproduce this, we'd recommend you try our test case and ensure it works as described here for you (if not you may need to ensure you're on the most recent nightly build).
      If it works for you, but your app does not, try modifying the simple test case attached here to more closely resemble your actual usage -- probably as simple as adding a field definition which matches the field which is failing for you, with the same set of validators, etc, and giving us steps to reproduce the problem [exact value you're entering before validation, etc].

      Regards
      Isomorphic Software

      Comment


        #4
        Another problem related to this is when I have 2 DynamicForms with a shared ValuesManager. When I call validate, the custom server validator on one of the DynamicForms appears to get called twice. But on the 2nd time, the data passed for validation are the unchanged values.

        Comment


          #5
          Unfortunately, we're still in a situation where we need a test case to reproduce your first claimed issue, let alone this new one.

          We've given you a starter test case, which shows no issue, in the post above.

          Comment

          Working...
          X