applySuggestionSelectedValue function
void
applySuggestionSelectedValue({})
Applies a picked suggestion the same way genericsuite-fe does: writes
the form field's own fieldName and only the keys listed in
autocomplete_fields. Related-table columns such as _id / name
are not copied onto the row.
Implementation
void applySuggestionSelectedValue({
required Map<String, dynamic> selectedItem,
required Map<String, dynamic> config,
required String fieldName,
required String encodedValue,
}) {
final Map<String, dynamic> valueMap = Map<String, dynamic>.from(
jsonDecode(encodedValue),
);
if (valueMap.isEmpty) {
return;
}
final dynamic description = valueMap[config['suggestion_desc_fieldname']];
if (description == null || description.toString().isEmpty) {
return;
}
final dynamic autocompleteFields = config['autocomplete_fields'];
if (autocompleteFields is Map) {
autocompleteFields.forEach((field, attrName) {
selectedItem[field.toString()] = valueMap[attrName] ?? '';
});
}
final String nameKey =
(config['suggestion_name_fieldname'] as String?)?.isNotEmpty == true
? config['suggestion_name_fieldname'] as String
: config['suggestion_desc_fieldname'] as String;
selectedItem[fieldName] = valueMap[nameKey] ?? description;
}