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

    Any callback for first fetch of ComboBoxItem?

    I have a ComboBoxItem with a changed() callback in it. The callback sets some hints for other fields based on the selected record. However, I need these hints to be set also when the form itself is opened with existing data. This form has a field with a value of (for example) 1. It starts fetching the display value for this record but at that point I would also set the hints.

    The simplest way to do this is to go ahead and fetch the related record yourself when you populate the form. But if you really want to avoid fetching data that the comboBoxItem also happens to be fetching, you could either set timers waiting for getSelectedRecord() to become non-null, or you could install a valueFormatter on the comboBoxItem - it happens to be re-run at the moment that the selected record has arrived, since formatters often rely on data in the selected record.


      Option 1 - I do know how to fetch a record myself, but how can I set the display value of the combo box as well? It would be nice if it could save one request.
      Option 2 - Setting timers sounds very strange these days. Using asynchronous requests, should fire callbacks in my opinion. Is this something that you would consider to add to the framework.
      Option 3 - Using a value formatter to set another field's hint, seems like a not-so-nice approach.


        As previously explained, what you call Option 3 would be the only way to do only one request given that the comboBox does an automatic fetch.

        There is also yet another approach which would be use to use DataSource.transformResponse to notice the comboBox’s fetch. Straightforward and clean.

        But just so you know, we are considering an API for a yet simpler notification that the comboBox has loaded the related record, to cover this edge case. It would be in a future version.


          The option of transformResponse sounds good! But in that method, how can I access the form?


            Any way you like.

            We're not sure what you need here, but obviously, it could be accessed if it had a known ID, or was made available from a static API, etc.