Cancel QSelect Selection?

  • Is there a way to be able to proactively cancel a selection in a q-select? So, the user selects something, a handler can do some checking, and the model gets changed ONLY if the handler approves; otherwise the model stays unchanged.

    I’ve googled, looked through the qselect code, and tried a few things like returning false from @input and adding a @change.native handler, but neither of those seem to work. I’ve also tried adding a rule, but that still allows the model to change even though I’m returning a string indicating an error.

    Thanks for any ideas!

  • @haigha-earwicket use lazy model ie. :value="model" @input="handler", where you do the actual change in your handler. You didnt need to google far enough, vue docs explained it there how v-model works.

  • @metalsadman that worked like a charm, thanks! I figured it supported it somehow, but I just couldn’t see it since I didn’t know quite what I was looking for. I still don’t see anything on that page that describes how v-model works though, except a small snippet down in the API box that doesn’t really describe much of use in this case. Perhaps adding an example of this use case under “The Model” section would be helpful for those like me who are still learning the best way of using Quasar in their projects.

  • @haigha-earwicket v-model is equivalent (usually called a syntactic sugar) for/to :value="model" @input="model = $event".

Log in to reply