Hello,
I'm looking for an text field (user input) which will auto suggest values (based on a database field). Afaik, that is something dropdown fields and with some more logical a customer picker can provide except they wont allow for new values to be entered.
What would be a good way (if any) to achieve this?
Discussion posts and replies are publicly visible
That requires some tricks. A custom picker field expects a datasubset returned from the suggest function. That datasubset has a field called "identifiers" which is of type ANY. This means that you can put your whole record in it, instead of just the ID.
When your user now looks for a non-existing item, you just have to add the entered search string to the field "data" and a new record (empty primary key!) to the identifiers field.
I use this to provide a field to enter keywords mixing existing and new ones.
Thank you, that helped. Basically what I did was to enhance the pattern recipe-configure-an-array-picker.html
(I did not yet needed an new record - but that is really nice to know that this would be achievable as well)
can you plx share some sample code for this?
Yes, but I'm not sure if my usecase fit yours. I've adopted the pattern a bit
That's is the search function (with the keyword (or filter) added to the result):
a!localVariables( local!matches: where( a!forEach( items: ri!labels, expression: search( ri!filter, fv!item) ) ), a!dataSubset( data: union(index( ri!labels, local!matches), ri!filter), identifiers: union(index( ri!labels, local!matches), ri!filter) ) )
Finally, I did not need to add the keyword to the customer picker because I was looking for a single value, so putting the result of the customer picker in a local variable was just fine for me:
a!pickerFieldCustom( label: "Country", labelPosition: "ADJACENT", maxSelections: 1, suggestFunction: rule!ucArrayPickerFilter( filter:_, labels: local!countryList ), selectedLabels: local!selCountry, value: local!selCountry, saveInto: local!selCountry, required: true )