lekoala / bootstrap5-autocomplete

Autocomplete for Bootstrap 5 (and 4!)
MIT License
87 stars 16 forks source link

data-label-field attribute is beign used as query parameter. #15

Closed guifsdev closed 1 year ago

guifsdev commented 1 year ago

First of all, thank you for this amazing component, that I been using for a time now. I have PhoneNumber resources coming from an api endpoint. I implemented a search functionality for these resources using Autocomplete as a component like this:

    <autocomplete-input
      type="text"
      class="w-100"
      id="test"
      data-live-server
      data-server="/admin/search"
      data-server-params='{"resource": "phone_number", "field": "phone_number"}'
      data-label-field="phone_and_name"
      data-value-field="id"
      :on-select-item="onSelectItem"
      placeholder="Customer phone number"
      data-not-found-message="No results found."
    />

I have the following PhoneNumber object as an example in which full_phone_number and phone_and_name are added attributes, that I generate after querying database and before responding from server.


    {
        "id": 1,
        "entity_id": 1,
        "entity_type": "App\\Models\\Customer",
        "country_code": "+55",
        "phone_number": "84959842668",
        "created_at": "2023-06-07T15:55:33.000000Z",
        "updated_at": "2023-06-07T15:55:33.000000Z",
        "full_phone_number": "+5584959842668",
        "br_format": "(84) 959842668",
        "phone_and_name": "(84) 959842668 | Luciano Chaves"
    }

So, in Autocomplete if I have the query like: '8495', I get a no results message regardless of a single result response in the inspector that indeed matches the field (phone_number) that was used in the component.

Captura de tela de 2023-06-07 14-28-02

I presume that, because data-label-field is set to phone_and_name, my query is checked against this key and not the intended one (field). The expected behavior was that the suggestion was shown no matter the value of the label associated with the result. The result should depend on field.

lekoala commented 1 year ago

i had the issue recently with ids as well (being numbers instead of strings) this should fix it https://github.com/lekoala/bootstrap5-autocomplete/releases/tag/1.1.10

lekoala commented 1 year ago

ah sorry read that too quickly

yes indeed the value itself is not found because it looks at the data. i will find a way to also look for the value

lekoala commented 1 year ago

i added a data-search-fields that accepts an array https://github.com/lekoala/bootstrap5-autocomplete/releases/tag/1.1.11

guifsdev commented 1 year ago

My sincere thanks for your invaluable contribution. Your update has greatly improved my application, and I am truly grateful for your assistance. Keep up the good work.

lekoala commented 1 year ago

:-) you are welcome, i also think it's a fine addition closing the issue