Use customPickerField with googleMaps

Hello, I am trying to implement a custompickerField, but I still don't understand very well how the suggestFunction and selectedLabels work since I have my DP_addressSugestion rule that receives the address and through the Google Maps API it already returns the filtering. Here is my suggestFunction.

a!localVariables(
  local!addressSugestion: rule!DP_AddressGoogleMaps(
    address: ri!address,
    latitud: -9.5,
    longitud: -75
  ),

  if(
    local!addressSugestion.success,
    a!localVariables(
      local!labels: a!forEach(
        items: local!addressSugestion.result.places,
        expression: index(fv!item, "description", null)
      ),
      local!values: a!forEach(
        items: local!addressSugestion.result.places,
        expression: index(fv!item, "description", null)
      ),

      a!dataSubset(
        data: local!labels,
        identifiers: local!values,
      )
    ),
    a!dataSubset(
      data: {},
      identifiers: {},
      totalCount: 0
    )
  )
)

Please help me to understand or some advices to work it

  Discussion posts and replies are publicly visible

Parents Reply Children
  • No problem. As the documentation says, suggestionFunction requires a function that executes a filtering or search rule for a certain array, and this function returns a datasubset with data and identifiers. In the case of Google Maps, this is much simpler since the API does the filtering for you, so you don't need to do much work. I'll leave the code for the ruleExpression and the interface.

    a!localVariables(
      local!addressSugestion: rule!DP_AddressGoogleMaps(
        address: ri!address,
        latitud: - 9.5,
        longitud: - 75
      ),
      if(
        local!addressSugestion.success,
        a!dataSubset(
          data: a!forEach(
            items: local!addressSugestion.result.places,
            expression: index(fv!item, "description", null)
          ),
          identifiers: a!forEach(
            items: local!addressSugestion.result.places,
            expression: index(fv!item, "description", null)
          ),
          
        ),
        a!dataSubset(data: {}, identifiers: {}, totalCount: 0)
      )
    )

    a!pickerFieldCustom(
          label: "Direccion Asistencia",
          suggestFunction: rule!DP_addressSugestion(address: _),
          selectedLabels: local!origin,
          value: local!origin,
          saveInto: { local!origin },
          maxSelections: 1
        )