Announcement

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

    Can a SelectItem return multiple fields per item

    We have a selectitem which uses a composite key. When we save the selectitem we need the id to be passed in along with the type in the return json. How is this possible?

    Here's some code with a few attempts we've made to achieve this:
    basic version, doesn't return type on saving of new item.
    Code:
    fields.add(new SelectItem("report", "Report"){{
    	setRequired(true);
    	setDataPath("report/id");
    	setValueField("id");
    	setDisplayField("name");
    	setOptionDataSource(new DataSource("theUrl"));
    }});
    multiple primary keys in datasource, doesn't work:
    Code:
    setOptionDataSource(new DataSource("theUrl"){{
    	setFields(new DataSourceTextField("id"){{
    		setPrimaryKey(true);
    	}}, new DataSourceTextField("type"){{
    		setPrimaryKey(true);
    	}});
    }});
    This works, but makes 2 posts.
    Code:
    selectitem.addChangedHandler(new ChangedHandler(){
    	@Override
    	public void onChanged(ChangedEvent event) {
    		form0.getField("report.type").setValue(event.getItem().getSelectedRecord().getAttribute("type"));
    	}
    });
    fields.add(new HiddenItem("report.type"){{
    	setDataPath("report/type");
    	setOptionDataSource(new DataSource("theUrl"));
    }});
    Last edited by saltwater; 30 Sep 2013, 09:39.

    #2
    When the user selects a record, use form.setValue() to store an additional value in the form (beyond the valueField that the SelectItem already stores).

    Comment


      #3
      I thought you couldn't create datapaths with setvalue, which was what we were trying to do, but it looks like you can.

      Code:
      form.setValue("report/type", stuff);
      Thanks

      Comment

      Working...
      X