1

I have few forms in my SPA, all are submitted via ajax.
This is the pattern I use:
<form @submit.prevent="submit">...</form>
and submit() will do something like $(form).serialize, to send the form data.

Usually it works fine, but have a problem - a custom component like vue-select: http://sagalbot.github.io/vue-select/
wont work, because it does not create a form field. So I have to add it manually to the form data. This has become a source of boilerplate code, and I want to avoid that.

The question: is there any way to make vue to auto-create data members based on the v-model of the inputs. Since I don't like the idea of duplicating the property names (both in v-model and in the vue instance). That's why I submit with serialize(), and don't use v-model, because it's easier for me to just create <input> elements with name attribute.

Or, to make the component to actually create a form field?
In general, is there a better way to handle forms with vue? (again, without duplicating v-model and data members?)

user3599803
  • 6,435
  • 17
  • 69
  • 130
  • 1
    Looks like you will have to use `v-model` to mirror the value from `vue-select` onto a hidden `` element, and then you're good to go: https://github.com/sagalbot/vue-select/issues/495. IMHO it looks like a gross oversight by the plugin author. – Terry Jun 09 '18 at 22:01

0 Answers0