No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    autocomplete with static-data updates model with label (text) not value (id)

    Framework
    2
    4
    315
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jriemer last edited by jriemer

      I use autocomplete with static-data, the data object looks like this:

      var customers = [
      	  { value:1, label: "Org one" }
      	, { value:2, label: "Org two" }
      ]
      

      In order for the autocomplete to filter on label I set the “field” attribute to “label” like this:

      <q-input v-model="idOrg">
      <q-autocomplete
            :static-data="{field:'label',list:customers}"
           :min-characters="0"
          @selected="selected"
        />
      </q-input>
      

      When selected the model (idOrg) gets updated with the label (text) not the value (id).
      I know I can create multiple “selected” methods or pass on arguments to it to change this (wrong) update to ID.
      Can I avoid this? How can I configure the autocomplete to filter by “label” but update with “value”?

      thanks
      jr

      1 Reply Last reply Reply Quote 0
      • s.molinari
        s.molinari last edited by

        Sorry I missed that the code above was your boot file. I’m no expert on Vuex, but that isn’t how the plug-ins can be added after the store has already been constructed.

        Have a look at this. https://stackoverflow.com/questions/50959594/dynamically-register-a-vuex-plugin

        Not sure it will work with that plug-in (as the answer also notes), but it might be worth a try.

        Scott

        1 Reply Last reply Reply Quote 0
        • J
          jriemer last edited by

          Thanks for your reply molinari.
          I don’t use Vuex, its a simple, out of the box Vue app with Quasar.
          Please see the following codepen: https://codepen.io/jriemer/pen/BEpXNe
          Goal: search by label (name), select the value (id)

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by s.molinari

            Oops. I posted in the wrong thread. 😃 Sorry about that.

            Not sure this is what you are looking for, https://codepen.io/smolinari/pen/WWpdVG.

            But, it gives you the value.

            Scott

            1 Reply Last reply Reply Quote 0
            • First post
              Last post