How to save one or more fields in the database using Vue.js

Asked

Viewed 109 times

1

I’m using a code in Vue.js that works as follows if I select a checkbox I can select the combobox, if I select the second checkbox, the second combobox appears and I can also select what is in the combobox.

My question is: If I select a checkbox I can save in the bank what is in the combobox ok, but what if I select both at the same time I am not succeeding. Would you like to know how I can do it? If I select the two fields I want to send the two filled combobox to the database. Could someone please help me? Thank you.

var app = new Vue({ 
   el: '#check', 
   data: { 
     checks: [ 
    	{label: '1 molho' , values: ['Rose' , 'Molho de Frango'] , check:false}, 
        {label: '2 molhos' , values: ['Rose' , 'Molho de Frango'] , check:false} 
     ]
   } 
  
})
<script src="https://cdn.jsdelivr.net/npm/vue"></script>

<div id="check">
  <div v-for="check in checks" >
    <label >{{check.label}}</label>
    <input type="checkbox" v-on:click="check.check = check.check == false ? true : false">
    <select v-if="check.check" name="tipo_molho">
      <option v-for="value in check.values " v-bind:value="value" >{{value}}</option>
    </select>
  </div>
</div> 

  • You have to post the problem code to get more help!

  • <div id="check"> <div v-for="check in checks" > <label >{{check.label}}</label> <input type="checkbox" v-on:click="check.check = check.check == false ? true : false"> <select v-if="check.check" name="type_sauce"> <option v-for="value in check.values " v-bind:value="value" >{value}} </select> </div> </div>

  • <script type="text/javascript" src="js/jquery-3.3.1.min. js"></script> <script type="text/javascript"> var app = new Vue({ el: '#check', data: { checks: [ {label: '1 sauce', values: ['Rose' , 'Chicken Sauce'] , check:false}, {label: '2 sauces' , values: ['Rose' , 'Chicken Sauce'] , check:false} ] } }) </script>

  • This is the code I must adjust or implement to make it work and the two combobox are sent to the bank if I select the two?

  • But what’s the problem? Is there an error in the console? Are you saving how? Because by Html and Js can not know what is happening.

  • So in the bank there is only one field that is type_sauce there when I select only one saved sauce ok in the bank, when I select the two sauces or be the two combobox ai saves only the first sauce. How do I save the two types of sauce in the bank? For example if the person wants only one saved sauce in the bank, but what if he wants two types of sauce or selecting the two combobox how do I save these two types of sauce in the bank using the same div??? I will have to create a condition or have to create another name in the div and then create another field there in the database, for example: type_molho2?

  • Or better in the same <select>. I tried to create another field and put two Names inside select but it did not work, is not saving the two combobox from the same select in the database

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.