Announcement

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

    SelectItem and setDataPath Client Issue

    SGWT: v10.0p_2014-10-22
    FF:26

    When switching back between records in the SelectItem, a record's value in the form changes. We're using setDataPath for the server-side only. Below is code to test. Reproduction steps include: Select 1, then 2, then 1; or Select 1, 2, 3.

    Code:
            Record record;
    	Record[] records = new Record[3];
    	DataSource ds = new DataSource();
    	
    	public void onModuleLoad() {
    		DataSourceField idField = new DataSourceField("id", FieldType.INTEGER, "Id");
    		DataSourceField nameField = new DataSourceField("name", FieldType.TEXT, "Name");
    		idField.setPrimaryKey(true);
    		ds.setFields(idField, nameField);
    		ds.setClientOnly(true);
    		for(int i = 0; i < 3; ++i) {
    			records[i] = new Record();
    			records[i].setAttribute("id", i);
    			records[i].setAttribute("name", "Foo"+i);
    		}
    		ds.setTestData(records);
    		new DynamicForm(){{
    			final DynamicForm form = this;
    			setFields(new SelectItem("recordId", "Record"){{
    				setRequired(true);
    				setDataPath("record/id");
    				setValueField("id");
    				//setDisplayField("name");
    				setOptionDataSource(ds);
    				addChangedHandler(new ChangedHandler() {
    					@Override
    					public void onChanged(ChangedEvent event) {
    						record = getSelectedRecord();
    						form.setValue("record", record);
    					}
    				});
    			}});
    		}}.show();	
    	}
    Thank you.

    #2
    Can you explain "we're using setDataPath for the server-side only". dataPath does not affect server behavior.

    Comment


      #3
      Originally posted by Isomorphic View Post
      Can you explain "we're using setDataPath for the server-side only". dataPath does not affect server behavior.
      The behavior seems to only occur when setDataPath is used in conjunction with form.setValue in the ChangedHandler. If either are excluded then the SelectItem behaves normally. See attached screen shots.

      screen-shot-1: initial screen shot.
      screen-shot-2: select item 1 and then select item 2.
      Attached Files

      Comment


        #4
        What were you expecting to happen here? Your dataPath setting means that the id of the record picked from the SelectItem will be stored at the path record.id in the form's values. Your ChangedHandler then immediately overwrites this.

        What's the purpose of this code? What are you trying to achieve here?

        Comment


          #5
          Just to clarify this a bit more: your dataPath setting means that the form will create a structure like record : { id : <i>selectedId</i> } to store the selectedId from the pickList.

          When you then overwrite the "record" property with a nested Record pulled from your DataSource, you are causing the form to start writing directly onto the DataSource data - with the results you experience - DataSource data has been modified by the form even though it's not bound to a DataSource.

          Since this whole code snippet appears very synthetic and odd, we're trying to figure out what you actually meant to achieve.

          Comment

          Working...
          X