CustomPicker with DB write

Hi Experts,

Do we have any Field where user can search for exiting list of values from database, and if value is not there in the list then whatever value user has typed in can be written to DB on the form submission. Later the value will become part of the list.

Thanks,

Gaurav Singh

  Discussion posts and replies are publicly visible

  • We do this in some situations where we want to show a pick list, but also allow the user to add their own value if what they are looking for is not available.  The trick is, within your a!pickerFieldCustom()'s searchFunction, append the search value to the data subset which is returned to the picker.

    One example is in a Meeting Minutes type app, where the meeting topic is selected via a picker, but we allow adding a new meeting topic within the picker also.  Something like:

    a!localVariables(
      local!data: a!queryEntity(...).data,
    
      local!topics: append(property(local!data,"topic",null),ri!search), /* Add the search to the data set!  It will be cleared below if it is found already */
      local!distinctTopics: reject(fn!isnull,rule!APN_distinct(local!topics)),
      local!top10: index(local!distinctTopics,enumerate(min(10,length(local!distinctTopics)))+1,null),
      a!dataSubset(
        startIndex: 1,
        batchSize: 10,
        totalCount: length(local!distinctTopics),
        data: local!top10,
        identifiers: local!top10
      )
    )

    Then on submission, you can query to see if the selection is already in the data source, if not, write it back.