0
I am using Boostrap and have a sector in the form where the client will choose some items, and when clicking on the item the bootstrap adds the class active in the selected item, and with css I make the item change color.
Getting kind of like this:
<label class="btn bg-grey active">
<input type="checkbox" name="tagslist[]" value="valor"> Titulo
</label>
I am using the Vue.js to create items dynamically through json data. And to automatically select checkboxes according to the open record.
But my problem is that in Vue.js when it starts leaving checked the items I need, it only does it in the checkbox, but does not add the active class in the label, thus staying:
<label class="btn bg-grey">
<input type="checkbox" name="tagslist[]" value="valor" checked> Titulo
</label>
How do I get him to add this class to the parent tag of this checkbox input?
Follow below the code working, see that when starting the checked items do not change color, only change when click on top, and still a bug that ends up changing color even if the item is not checked.
new Vue({
el: '#v-for-tags',
data: {
seltags: ["feminino","masculino"],
tagsitens: {"codes":{"feminino":{"tagtitulo":"Mulheres","tagslug":"women"},"infantil":{"tagtitulo":"Crianças","tagslug":"childs"},"masculino":{"tagtitulo":"Homens","tagslug":"men"}},"list":["feminino","infantil","masculino"]}
}
});
.btn.bg-grey.active {
background-color: #673ab7 !important;
}
.iconsdinamic {
float: left;
margin-left: 10px;
}
<div class="btn-group-toggle" data-toggle="buttons" id="v-for-tags">
<div v-for="(option, keyoption) in tagsitens.codes" class="iconsdinamic">
<label class="btn bg-grey">
<input type="checkbox" name="tagslist[]" autocomplete="off" v-bind:value="keyoption" v-model="seltags"> {{ option.tagtitulo }}
</label>
</div>
</div>
<!-- --------------------------------------------- -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
Please help me out. Thank you
Thank you, I just have one more question. that way you put it does a if the selected data is equal to the value ne so it creates the dynamic data? Is there any way that if monitor when the checkbox is active even after it is created? So, if you press on the checkbox box, it changes the color showing this selected but does not check the checkbox.
– Samanta Silva
Yes, yes, I know. Your answer already helps me a lot, but I asked if there was a way to monitor the click by checkbox check, it would be even better. I asked more to know. But if there’s no way it’s okay anyway. ^^
– Samanta Silva
I didn’t think to use Boostrap-Vue, because I’d have to change everything that’s ever been created, wouldn’t I? The site is almost ready with boostrap and Vue separated. I’m afraid of changing and end up harming the whole site.
– Samanta Silva
It’s I think he just monitors the click on the button by the class btn-group-toggle. I think boostrap did it to use this active on anything that uses this class. I think if I could make you monitor the checkbox check, I could take the toggle out of the boostrap and use it just for Vue. I don’t know if it would work.
– Samanta Silva
@Samantasilva see now how this! I believe that now everything is right.
– NoobSaibot
Thanks buddy, everything worked out, yeah, perfect, helped me a lot to solve the two problems that I was breaking my head. Thank you for your patience in helping me ♥
– Samanta Silva