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.
Announcement
Collapse
No announcement yet.
X
-
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.
Comment
-
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.
Comment
Comment