board logo
WUICTeam
  • WUICTeam
  • 100% (Exalted)
  • Newbie Topic Starter
20 days ago
Update: the documentation of slimCombo together with a computed display formula has been corrected. Fixed in WUIC Framework 1.8.2 .
The original answer below describes versions before 1.8.2.

Question
I have a lookup on a product column and I want to fill the description, unit price and VAT code of the row when the user picks a product. Is there a way to read those values from the selected record without a second request to the server? The properties I need are not the lookup's value or text field, and they come back undefined.

Answer
Yes: list the extra columns in mc_props_bag.slimCombo and read them from <column>__lookup_obj inside mc_selection_changed_custom_function__fn.

By default the lookup dropdown runs a slim SELECT on the related table: the primary key, mc_ui_lookup_dataValueField and mc_ui_lookup_dataTextField only. That keeps the payload small, but it also means any other column of the product is simply not in the record you get on selection. slimCombo is an array of extra column names added to that SELECT:


{
  "slimCombo": ["unita_misura_id", "codice_iva_id", "prezzo_vendita"]
}

Then, in the selection-changed callback, the selected related record is available as record['<column>__lookup_obj'].value:


prodCol.mc_selection_changed_custom_function__fn = (record, _f, _m, newValue) => {
  const prod = record['prodotto_id__lookup_obj']?.value;
  if (!prod) return;
  record['prezzo_unitario']?.next(prod.prezzo_vendita);
  record['codice_iva_id']?.next(prod.codice_iva_id);
};

Things to watch
  • slimCombo lives at the top level of mc_props_bag, not under lookup. Placed under lookup it is silently ignored.
  • If the property is undefined, first check that the column name is spelled in slimCombo exactly as in the related table.
  • slimCombo: false turns the restriction off and the combo returns every column: handy for debugging, heavier on the wire.
  • If the column uses mc_ui_lookup_combo_text_edit_computed_dataTextField and no slimCombo array, the combo returns all columns because the formula may reference any of them.


The trade-off is a slightly larger combo response, in exchange for no extra by-id request on every selection.

Documentation: Widget Lookup