Announcement

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

    picklist multiple valueFields??

    Is there a way to simply access the returned value from one of the display fields in a databound combo/select list.

    For example, i have a currency table, which is beinged use to populate a select item for currency, this uses an primary key value as the stored valueField, and displays the currency code/symbol. Additionally the exchange rate is in the Display list of the select item. There is another field in my form that i want to set as the FX rate whilst also continuing to set the currency primary key id for the current field.

    I have a "change()" function on the currency field in question, however i don't seem to be able to reference values from the display field list of the picklist item, so that i can set the other FX Rate field.

    Is this possible? I guess the alternate approach would be to have another call tot he database after selecting the currency to fetch again the FX rate and pop to the FX Rate field?

    Attached is a shot of my play page, the currency code, name and fx rate are in the picklist display fields, the currencyID is set to this field value. THe fx rate though i want to set into the next field in the page called FX rate...
    Attached Files

    #2
    onChange event, you can use

    changed :function(form,item,value) {
    var listdata = item.getClientPickListData() ;
    var thisrec = listdata.find(item.name,value);
    var fxval = thisrec.fxval;
    form.setValue(fxvaluefield,fxval);
    }

    Comment


      #3
      Almost

      Tried this already, the clientpicklistdata object only contains the returned records for the valueField, it's another field from the datasource/results set that i am attempting to access. Is there a method that allows me to FIND on the resultset of the optiondatasource attached to this picklist, and find the data i need from there..

      In the callstack, the datasouce is returning the records and i can see that in the localData on the datasource the from_currency_id, currency_code and fx_rates are locally loaded.

      Comment


        #4
        The dataArrived event would allow you to get to the complete set of data (assuming there's no need for paging, which seems unlikely).

        If you're going to be working with the dataset directly a lot instead of having it automatically managed, consider just calling DataSource.fetchData() directly, since the DSResponse has a getRecordList() method which will allow you to get a valueMap from the returned data easily, which you could use with the SelectItem in lieu of using optionDataSource.

        Comment


          #5
          ok

          ok, so this is what i did, basically set a "dataArrived" event override to the Combo, then, on arrival i set another recordSet called FXRATES to the complete recordlist returned. Not worried about paging as i am a) testing this code out and b) there are a limited total number of currencies in the world.

          Question i have though now is thus, is it better to use getRange on the resultset?? and have it refetch? or use the dataArrived approach, the reason i ask is that i had to use the following to make it work

          dataArrived: function (start, end, data) {
          fxrates.localData=data;
          },

          Note: the localData, i basically set it directly. Initially i had hoped that because i tied the result set to the datasource (SAME) for the combo, that on fetch it would automatically pop my resultSet, nope....

          anyway, the following CHANGED code works

          var thisrec = fxrates.find("from_currency_id", value );
          var fxval = thisrec.fx_rate;
          header.setValue("fx_rate",fxval);

          Questions i have are
          1) is this efficient, i guess if there is an extremely long dataset that this might case some issues, although i wouldn't expect in this instance.
          2) is there some enhancement that you can make to the combo.picklist object, so that on a fetch that includes display fields, that these display fields and the value field are stored in the picklist.data, so that getClientPickList data would have allowed me to implement the above in like 3 lines of code and would only need the one LIST on the pickitem, rather than now one on that, one for the display (notaccessible currently in SCV7) and the new one i had to create for find operations post dataArrived.

          Should i add that to the wish list....

          Comment


            #6
            You definitely do not want to set "localData" on a ResultSet (if that's what "fxrates" is) as that is an internal property. You can create a ResultSet with initialData instead.

            However, your best path for simplifying this code is not to add new APIs to the ComboBox, but to stop using optionDataSource for this case, as previously indicated.

            Comment


              #7
              But

              But the result set is pretty dynamic, in that on changes to 2 fields in the form, i want the result reset refreshed. And other fields in the form updated accordingly. Result sets "custom" dont' automatically refresh from fetches on their associated datasource, hence i'd need for each change in the fields a fetch, then resultSet.get(xx), resultSet().find(xxx,xx). It seems over the top, given that the values i need are present within the select lists optiondatasource, whether this select is automatic or manually managed.

              Is there a way to reference the entire LIST object, for the selectitem, other than getPickListListData? as this method only returns the "VALUE_FIELD" values, when it's all the fields in the select items underlying resultset that i want to reference then use.

              I shall in the meantime implement the manually managed resultset/datasource/select/combobox methods as you stated... i'm assuming that when i have the fetch on the datasource i do something like this in the call back

              fx_datasource.fetchData({effective_date: xxxxx}, "fxrates_resultSet.allrows=data");

              attempting to use a callback that sets fxrates_resultSet.data does nothing useful, as the fxrates_resultSet.find(xx,xx) does not look in the object data, it looks in the object localData.

              Comment


                #8
                If you're more comfortable with the pattern offered by optionDataSource, that's fine, the recommendation is still not to assign to internal variables (localData) and never to assign directly to properties without using either setters or the setProperties() helper (see the docs under "flags"). There is no need for either, and neither simplifies yor code, just makes it
                less maintainable.

                Comment


                  #9
                  Any Update on This

                  Is there any update on this? Or could you explain how people are using a combobox, where after selection multiples of values from the picklist of the combobox are being used to populate various fields in a form or grid?

                  Comment


                    #10
                    Possibility to get the Code... pretty plz

                    Hey mgscott,

                    This looks like what I need... any possibility to get a peek at some of your code?

                    It would help me out a lot!!!

                    Thanx
                    Bart

                    Comment


                      #11
                      Hi bade, hi mgscott,

                      Iīve got something for you. We created a combobox with several column and when the user selects an entry, the values are sent to other form fields.
                      For example: you have a form with 3 input fields (address, street, area code) and one combobox (with person names in it). Now, when the user selects a combobox entry, we get the recordset and split colums/values. Then we set the selected personīs address, street and area code.
                      If this is what you are looking for... here is some code:

                      Code:
                      ...
                      import com.smartgwt.client.widgets.form.fields.SelectItem;
                      import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
                      import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
                      import com.smartgwt.client.widgets.grid.ListGrid;
                      
                      public class SuggestBoxChangedHandler implements ChangedHandler {
                      ...
                      private ListGrid currentListGrid = new...;
                      ...
                      	public void onChanged(ChangedEvent aEvent) {
                      		if (new SelectItem(aEvent.getItem().getJsObj()) != null){
                      			SelectItem curItem = new SelectItem(aEvent.getItem().getJsObj());
                      
                      			if (curItem.getSelectedRecord() != null){
                      				if(currentListGrid != null){
                      					int editRow = currentListGrid.getEditRow();
                      					currentListGrid.setEditValue(editRow, getCreditorNameField(), curItem.getSelectedRecord().getAttribute("name"));
                      					currentListGrid.setEditValue(editRow, getCreditorBicField(), curItem.getSelectedRecord().getAttribute("bic"));
                      					currentListGrid.setEditValue(editRow, getCreditorIbanField(), curItem.getSelectedRecord().getAttribute("iban"));
                      				}
                      			}
                      		}
                      	}
                      Important! This class is a ChangedHandler added to the combo box ;-)
                      If any questions, just scream!
                      Last edited by GWTDummies; 8 Jun 2010, 06:25.

                      Comment

                      Working...
                      X