Prevent user from selecting duplicate values in custom picker

I have a custom picker field that returns a list of users, 

 I want to be able to prevent the user from selecting the same user more than once. 

 

 Scenario: 

Users: "John", "James","Sally" 

 

User comes in and selects "John" as a user on the picker field, then presses "j" the only user that should display is "James". How can I achieve this? 

  Discussion posts and replies are publicly visible

  • Hello Jawara,

    Option 1)
    Let's think your picker saveInto:local!arrray
    Try union (local!arrray, local!arrray)
    This will make your users able to select the same but you will save it just once.

    Option 2)
    In the custom picker in the suggestFunction send the current list, and when you query the DB or service or even in memory filter out those already selected values

    Jose
  • May be following code works for you : 

     

    load(
    a!formLayout(
    firstColumnContents: {
    a!pickerFieldCustom(
    label: "Select User",
    suggestFunction: rule!TEST_pickerSuggestFn(
    searchText: _,
    selectedUsers: ri!selectedUsers
    ),
    selectedLabels: ri!selectedUsers,
    value: ri!selectedUsers,
    saveInto: ri!selectedUsers
    )
    }
    )
    )

    selectedUsers - User (List)

     

    rule!TEST_pickerSuggestFn

    with(
    local!users: {
    touser(
    "John"
    ),
    touser(
    "James"
    ),
    touser(
    "Sally"
    )
    },
    local!userData: fn!difference(
    local!users,
    ri!selectedUsers
    ),
    local!matches: where(
    apply(
    search(
    ri!searchText,
    _
    ),
    local!userData
    )
    ),
    a!dataSubset(
    data: index(
    local!userData,
    local!matches
    ),
    identifiers: index(
    local!userData,
    local!matches
    )
    )
    )

    searchText - Text

    selectedUsers - User (List)

  • You can use thi code in save into of custom picker

    a!save(
    ri!selectedId,
    union(save!value, cast(typeof(save!value), {}))
    )