ComboBoxItem.getSelectedRecord() does not return correct record when valueField contains duplicate entries.
I am using SmartGwt Pro 6.3.2013, but the issue dates back to SmartGwt 2.2. The use case is that we are using an optionDataSource to look up a user. This user may have several entries if he possesses several roles. We wish to populate secondary formfields with values from the selected record pertaining to roles. Even if the optiondataSource has a unique primary key, the getSelectedRecord() on the ComboBoxItem will always return the first entry in the picklist matching the valuefield chosen.
I have attached a small sample to reproduce the issue.
I have also coded a workaround in jsni by overriding ComboBoxItem.getSelectedRecord(), but I am uncomfortable with this solution, as it may break at any time. Would you consider including something along the line of the following if it does not break any other functionality?
Regards
Hans Petter Simonsen - Evry Norway
I am using SmartGwt Pro 6.3.2013, but the issue dates back to SmartGwt 2.2. The use case is that we are using an optionDataSource to look up a user. This user may have several entries if he possesses several roles. We wish to populate secondary formfields with values from the selected record pertaining to roles. Even if the optiondataSource has a unique primary key, the getSelectedRecord() on the ComboBoxItem will always return the first entry in the picklist matching the valuefield chosen.
I have attached a small sample to reproduce the issue.
I have also coded a workaround in jsni by overriding ComboBoxItem.getSelectedRecord(), but I am uncomfortable with this solution, as it may break at any time. Would you consider including something along the line of the following if it does not break any other functionality?
Code:
@Override public ListGridRecord getSelectedRecord() { if(JSOHelper.getAttribute(this.getJsObj(),"pickList") == null) { // Prevent premature fetch if picklist has not been opened return null; } else { return jsniGetSelectedRecord(); } } public native ListGridRecord jsniGetSelectedRecord() /*-{ var self = this.@com.smartgwt.client.core.DataClass::getJsObj()(); var ret = null; if(self._value != null && self.optionDataSource) { if(self.pickList && self.pickList.data) { ret = self.pickList.getSelectedRecord(); if (ret != null) { if (ret.valueField != self._value) { // $wnd.isc.ComboBoxItem.logWarn("Stale selectedRecord on " + self.getID() + " Record valueField:" + ret.valueField + " Item value:" + self._value); ret = null; } } } } if(ret == null || ret === undefined) return null; var retVal = @com.smartgwt.client.core.RefDataClass::getRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret); if(retVal == null) { retVal = @com.smartgwt.client.widgets.grid.ListGridRecord::new(Lcom/google/gwt/core/client/JavaScriptObject;)(ret); } return retVal; }-*/;
Hans Petter Simonsen - Evry Norway
Comment