Coder Social home page Coder Social logo

Comments (15)

stefandunn avatar stefandunn commented on July 18, 2024 8

I managed to come up with a work-around by setting the ref attribute on the component and then using this.$refs.refName.inputValue = 'Some value'.

<vue-bootstrap-typeahead 
    v-model="town"
    :data="towns"
    :inputClass="'large-input'"
    placeholder="Enter your town or city"
    ref="townTypeahead"
/>

Then in the mounted() lifecycle, use:

this.$refs.townTypeahead.inputValue = 'London'

from vue-bootstrap-typeahead.

jonbartlam avatar jonbartlam commented on July 18, 2024 6

Would love to know if this is actually something we've both misunderstood. Great component but this feels like a basic feature that should work? I've just had exactly the same issue - despite setting v-model to the text I wanted displayed, it simply wouldn't show the value. I've found a work around by looking at the sourcecode but I'll add a warning:

Those of a weak disposition, look away now. Those easily offended should also look away.

My component setup is like this:

Component/HTML
<vue-bootstrap-typeahead ref="typeahead" :data="addresses" v-model="addressSearch" :serializer="s => locationText(s)" @hit="locationSelected" />

Where you want to set the initial selection
this.$refs.typeahead.$data.inputValue = this.locationText(val)

LocationText() is just a method I'm using to format the text as I want it - nothing special

Now that's out of the way - here's my use case incase I misunderstood you:

  • User clicks a record from a table and a record is retreived from the database. Part of the record contains an id to a location object and the location object itself (basically, a region and postcode/zip code).
  • Form is loaded with record and the location object's text representation is shown (concatenated text) inside the typeahead.
  • User clicks in field to edit and when typing it will suggest records.
  • On select, the id of the record selected is put into the location id field.

But obviously, when binding the initial location object, nothing was coming up. I found the only way to do it was reaching inside the typeahead component and setting the value it uses internally. I'm not sure what effect this will have on other aspects, but it works for me. I'm using NUXT FWIW

from vue-bootstrap-typeahead.

joelhickok avatar joelhickok commented on July 18, 2024 4

I managed to come up with a work-around by setting the ref attribute on the component and then using this.$refs.refName.inputValue = 'Some value'.

<vue-bootstrap-typeahead 
    v-model="town"
    :data="towns"
    :inputClass="'large-input'"
    placeholder="Enter your town or city"
    ref="townTypeahead"
/>

Then in the mounted() lifecycle, use:

this.$refs.townTypeahead.inputValue = 'London'

This is great, but we shouldn't have to be doing this. v-model should just work on this component... so there is a bug in there somewhere, although I just started using this and didn't look at the code.

from vue-bootstrap-typeahead.

natha9404 avatar natha9404 commented on July 18, 2024 2

I managed to come up with a work-around by setting the ref attribute on the component and then using this.$refs.refName.inputValue = 'Some value'.

<vue-bootstrap-typeahead 
    v-model="town"
    :data="towns"
    :inputClass="'large-input'"
    placeholder="Enter your town or city"
    ref="townTypeahead"
/>

Then in the mounted() lifecycle, use:

this.$refs.townTypeahead.inputValue = 'London'

This doesn't working for me :/, some idea?

from vue-bootstrap-typeahead.

mattzollinhofer avatar mattzollinhofer commented on July 18, 2024 2

I believe that I've merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try and let me know if this is still an issue!

You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.

I hope this helps!

from vue-bootstrap-typeahead.

jonbartlam avatar jonbartlam commented on July 18, 2024 1

@stefandunn Much neater fix. I hadn't thought about just omitting the $data (I'm still picking vue up). Cheers.

I also note that there is a branch of this project with this issue updated but it hasn't been merged.

from vue-bootstrap-typeahead.

StrongLucky avatar StrongLucky commented on July 18, 2024 1

I believe that I've merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try and let me know if this is still an issue!

You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.

I hope this helps!

Thank you. This is working!

from vue-bootstrap-typeahead.

juanca2626 avatar juanca2626 commented on July 18, 2024 1

Creo que he fusionado una solución para esto en mi fork ( https://github.com/mattzollinhofer/vue-typeahead-bootstrap ) de este proyecto que mantengo activamente. Pruébalo y avísame si esto sigue siendo un problema.

Puede encontrarlo en npm aquí: https://www.npmjs.com/package/vue-typeahead-bootstrap .

¡Espero que esto ayude!

Perfecto funciona !!!

from vue-bootstrap-typeahead.

bogdancarmanus avatar bogdancarmanus commented on July 18, 2024

That's exactly the case. Thanks for coming up with the detailed description.

from vue-bootstrap-typeahead.

raymondmuller avatar raymondmuller commented on July 18, 2024

#21

from vue-bootstrap-typeahead.

AraneaDev avatar AraneaDev commented on July 18, 2024

#32

from vue-bootstrap-typeahead.

siamkreative avatar siamkreative commented on July 18, 2024

@alexurquhart Is this repository no longer maintained?

from vue-bootstrap-typeahead.

mattzollinhofer avatar mattzollinhofer commented on July 18, 2024

I just double checked this issue and it is resolved on my branch. You can now set the initial value and update it as necessary. Report any more issues here https://github.com/mattzollinhofer/vue-typeahead-bootstrap/issues

from vue-bootstrap-typeahead.

pappascd81 avatar pappascd81 commented on July 18, 2024

I believe that I've merged a fix for this into my fork (https://github.com/mattzollinhofer/vue-typeahead-bootstrap) of this project that I'm actively maintaining. Give it a try and let me know if this is still an issue!

You can find it on npm here: https://www.npmjs.com/package/vue-typeahead-bootstrap.

I hope this helps!

That broke the serializer. It now shows [Object object].

from vue-bootstrap-typeahead.

mattzollinhofer avatar mattzollinhofer commented on July 18, 2024

That broke the serializer. It now shows [Object object].

@pappascd81: Interesting, it's working well on my end and others are reporting success. If you can provide a few more details as a new issue on the new repo I can try and see what's going on: https://github.com/mattzollinhofer/vue-typeahead-bootstrap/issues

from vue-bootstrap-typeahead.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.