vue.js v-bind:value is not working with select option form element

Anargu

I have a strange problem, watching at the tutorials of vue.js here: https://vuejs.org/v2/guide/forms.htmlthe the following code should work:

<div class="input-field">
    <select v-model="selected">
         <option v-for="couponType in couponTypes" v-bind:value="couponType" value="">{{ couponType }}</option>
         </select>
         <label>Tipo de cupon</label>
</div>

this template works with the following script:

<script>
export default {
    data: function () {
        return {
          couponTypes: [ "V333333333333é",
           "Vasdasdasd",
           "V211111111Café",
           "444444444444444444"
          ],
          selected: "",
          newCoupon: {
            couponTypeSelected: "",
            userId: ""
          }
        }
    },
    methods: {
      SendCoupon: function () {
        console.log(this.newCoupon)
        console.log(this.selected)
      }
    },
    created: function () {
      $(document).ready(function() {
        $('select').material_select();
        $('.modal').modal();
      });
    }
}

When sendCoupon() is triggered it supposedly selected variable should print the value of the selected option in the select element, but it only prints an empty string that is the initial setted value.

Anargu

After days searching about a solution I found that the cause of this error is the use of materializecss with vue.js on the templates. According to this reported issue ( github reported isssue ), materialize css modify the DOM when there is a select or ul (list) on the template of a .vue component. In the reported issue on Github there is a workaround: add browser-default as a class to the select element,this disables to materialize to modify the DOM element, then binding of vue could work. Here I drop an example.

              <div class="input-field">
                <select class="browser-default" id="selectoption" v-model="newCoupon.coupon">
                  <option v-for="selected in couponTypes" v-bind:value="selected">{{ selected }}</option>
                  <label for="selectoption">Cupon</label>
                </select>
              </div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Setting 'selected' option for select element in Vue.js

From Dev

Vue.js v-bind to a value within an array

From Dev

Angular JS: Pass a forms select option value to database not working

From Dev

Angular JS: Pass a forms select option value to database not working

From Dev

Vue JS how to change value of varaible on chosen select's option

From Dev

Knockout -> Bind element to Value of Select

From Dev

vue js display obj-array value v-select

From Dev

IE Select Box option element height not working

From Dev

IE Select Box option element height not working

From Dev

Vue 2.0 bind value prop to custom element

From Dev

Simple form: bind collection select choices to a value

From Dev

How to display the value of select option on value input text ? (vue.js 2)

From Dev

How to trigger an action by clicking the option item of a select element (Vue.js)?

From Dev

Custom Vue select component not updating selected option when v-model value changed

From Dev

show option value selected in form select

From Dev

Codeigniter in select option default value not working

From Dev

How can I add a disabled option when populating a select with Vue.js v-for

From Dev

How to get option value of select element

From Dev

Access value of selected option in <select> element with PHP

From Dev

Knockout : Bind data object with select element's option

From Dev

Knockout : Bind data object with select element's option

From Dev

Vue.js option component for select

From Java

Vue.js: Passing Object with Symbol type value with v-bind

From Dev

Vue.js selected option not based on value

From Dev

Make form invalid when select option select to 0 value

From Dev

Select2 autocomplete not working when bind element names are different

From Dev

Select2 autocomplete not working when bind element names are different

From Dev

Not able to post the select option value in express js

From Dev

Access select element value on form submit

Related Related

  1. 1

    Setting 'selected' option for select element in Vue.js

  2. 2

    Vue.js v-bind to a value within an array

  3. 3

    Angular JS: Pass a forms select option value to database not working

  4. 4

    Angular JS: Pass a forms select option value to database not working

  5. 5

    Vue JS how to change value of varaible on chosen select's option

  6. 6

    Knockout -> Bind element to Value of Select

  7. 7

    vue js display obj-array value v-select

  8. 8

    IE Select Box option element height not working

  9. 9

    IE Select Box option element height not working

  10. 10

    Vue 2.0 bind value prop to custom element

  11. 11

    Simple form: bind collection select choices to a value

  12. 12

    How to display the value of select option on value input text ? (vue.js 2)

  13. 13

    How to trigger an action by clicking the option item of a select element (Vue.js)?

  14. 14

    Custom Vue select component not updating selected option when v-model value changed

  15. 15

    show option value selected in form select

  16. 16

    Codeigniter in select option default value not working

  17. 17

    How can I add a disabled option when populating a select with Vue.js v-for

  18. 18

    How to get option value of select element

  19. 19

    Access value of selected option in <select> element with PHP

  20. 20

    Knockout : Bind data object with select element's option

  21. 21

    Knockout : Bind data object with select element's option

  22. 22

    Vue.js option component for select

  23. 23

    Vue.js: Passing Object with Symbol type value with v-bind

  24. 24

    Vue.js selected option not based on value

  25. 25

    Make form invalid when select option select to 0 value

  26. 26

    Select2 autocomplete not working when bind element names are different

  27. 27

    Select2 autocomplete not working when bind element names are different

  28. 28

    Not able to post the select option value in express js

  29. 29

    Access select element value on form submit

HotTag

Archive