PickerfieldCustom not working as expected

Hi all ,

I am working on a use case wherein I require that country names are auto-suggested on typing the initial characters of the country. But my code is not behaving as expected and the suggested countries are not accurate. Please go through it. Any help is much appreciated.

The interface rule is as follows :

load(
  local!OrganisationPicker,
  local!CountryPicker,
  {
    a!pickerFieldCustom(
      label: "Country",
      labelPosition: "ABOVE",
      placeholder: "--Type to search for country--",
      maxSelections: 1,
      suggestFunction: rule!getCountryByFilter(
        country: _
      ),
      selectedLabels: local!CountryPicker,
      value: local!CountryPicker,
      saveInto: {
        local!CountryPicker
      }
    ),
    a!textField(
      value: local!CountryPicker,
      readOnly: true,
      label: "CountryPicker"
    )
  }
)

The suggest function used here is

load(
  local!query: a!queryEntity(
    entity: cons!ABC,
    query: a!query(
      logicalExpression: a!queryLogicalExpression(
        operator: "AND",
        filters: {
          a!queryFilter(
            field: "domicileCountry",
            operator: "includes",
            value: ri!country,
            applyWhen: not(
              rule!APN_isBlank(
                ri!country
              )
            )
          )
        }
      ),
      pagingInfo: a!pagingInfo(
        1,
        20
      )
    ),
    fetchTotalCount: true
  ),
  a!dataSubset(
    data: rule!APN_distinct(
      index(
        local!query.data,
        "domicileCountry",
        {}
      )
    ),
    identifiers: local!query.data,
    totalCount: length(
      rule!APN_distinct(
        index(
          local!query.data,
          "domicileCountry",
          {}
        )
      )
    )
  )
)

Thanks in advance,

Ishani Joshi

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    At first glance, I notice you're using the "includes" operator in your one Query Filter in the Suggest Function.  This will cause the query to return any country containing the letter(s) typed by the user, i.e. if the first letter typed by the user is "a", it will at first query every country with an "a" in its name, whether or not it starts with "a" - so everything from "argentina" to "uganda" etc.

    If your intent is that the user query matches the start of the country name, you should use the "starts with" operator instead.

Reply
  • 0
    Certified Lead Developer

    At first glance, I notice you're using the "includes" operator in your one Query Filter in the Suggest Function.  This will cause the query to return any country containing the letter(s) typed by the user, i.e. if the first letter typed by the user is "a", it will at first query every country with an "a" in its name, whether or not it starts with "a" - so everything from "argentina" to "uganda" etc.

    If your intent is that the user query matches the start of the country name, you should use the "starts with" operator instead.

Children