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

    Event order in ComboBoxItem

    We have problem that 'changed' event on ComboBoxItem is fired only after user interaction not after setting value from framework. We would like to fire 'changed' event also after directly setting value. Because function in changed is using selectedRow (other columns from pickList) we need to fire it after data are loaded in dataArrived() callback. However it's not working well. We have to check many conditions not to fire changed also when normal pick list is loading - it's mess.

    Isn't here some simple setting which will fire 'changed' event after value is changed by user inteteraction and also after direct setting value a way that selectedRow will always return correct row?

    Thank you

    Changed is intended to fire only in response to user interaction.
    It sounds like you're already taking the correct approach:

    - If you're programmatically setting to a value via a call to 'setValue()' [or 'setValues()' / 'editRecord()' etc on the form], your calling code can also trip whatever custom logic you need to occur.
    If this is complex to achieve in your app, another option would be to override 'setValue()' on the item to trip your custom logic.

    - In terms of the case where you have a ComboBoxItem with an optionDataSource, you can use the "dataArrived" handler and "getSelectedRecord()" to be notified when remote data is fetched.

    It should be possible to make this work with your application code without it being "messy" - we can't comment on exactly how to clean up your code, but in short if you're taking the current selected record and applying it to some other component a common function called from both dataArrived and changed which checks for 'getSelectedRecord()' returning a non null value that doesn't match the record currently being displayed elsewhere in your app should do it.


      Problem with dataArrived is that you have to recognize situation when data arrive only because you opened PickList or other situations when data are needed and situation when dataArrived is called because you set new 'unknown' value to field.
      To be honest we aren't able to recognize this two situations correctly.

      Plus you have still situation when dataFetch isn't necessary. setValue override where you detect selectedRecord IS available.

      Just too much surrounding code. Will be nice to have some option to fire changed also from non user interaction because all code is in 'changed' event handler. Of course I'm doing all magic with SmartGWT what is another layer above all this problems :-/.


        It sounds like you're looking for something like a "selectedRecordChanged" type event handler.
        Please consider adding a feature request to the Wishlist forums.

        In the meantime it seems like you should be able to achieve this with application level code. The exact implementation would vary but broadly speaking, the 'selectedRecord' can change on setValue, on dataArrived or on 'changed'.
        Therefore in each of these places you can call 'getSelectedRecord()' - if it returns null, you have no selected record. If it returns a record, you know that record is current and up to date.
        If the concern is that your logic will fire too often you can cache the selected record somewhere, then when these methods are fired and 'getSelectedRecord()' returns a record you can compare with the cached record and only fire your special logic if the selected record changed.
        How you compare the records would depend on your application. If your optionDataSource has a primary key you could compare primary keys. Alternatively you could cache the item value along with the selected record, and clear/update the record when the value changes.

        By the way - we didn't realize you were working in SmartGWT rather than directly SmartClient. It doesn't actually make any difference to this issue, but for future issues we'd recommend posting to the SmartGWT forum so we're aware that you're working with SmartGWT

        Isomorphic Software


          I will write it in Wishlist forum.
          It looks feasible but difficult. I expected it should be already build in, that's why I asked here not in SmartGWT forum.

          Thank you for response and advices.


            Hello Pavel,
            I think this link might be useful to you.


              Thanks, this part is easy.
              Problem is when you need getSelectedRow() in 'changed' function. Than you have to override also dataArrived and problems begins ;-).