So I'm using Vue and Bootstrap-Vue. The context: This is a register page which I have 2 tabs, where when the first tab is completed then you can hit the button and pass to the second tab. The second one have the 'disabled' attribute, and when I click on my button it should enable the tab. I tried to do a javascript function, but it doesn't seem to be right.
My code is on Fiddle, and also here it is the relevant portion of the code.
<b-tabs class = "the-tabs-group" v-model="tabIndex">
<b-tab title="Primeira Fase" active>
<div class="form-group row">
<label class="col-sm-1 col-form-label">Email:</label>
<div class="col-sm-9">
<input type="email" class="form-control " id="email" name="email">
</div>
<hr>
<label class="col-sm-1 col-form-label">Senha:</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="pwd" name="pwd">
</div>
<hr>
<label class= "confirmsenha col-sm-1 col-form-label">Confirmar senha:</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="cpwd" name="cpwd">
</div>
</div>
</b-tab>
<b-tab id="segundaFase" title="Segunda Fase" disabled >
<div id = "bb">
<h1>Quase lá!</h1>
<p>Loren ipsum sit amet,consecteur adisplinig elit.Etiam eget commodo nignbi phometehues</p>
</div>
</b-tab>
</b-tabs>
<div class="next">
<a>
<b-btn id="nois" class="btn-link" @click="tabIndex++; enableTab">Próxima Fase</b-btn>
</a>
</div>
<script>
new Vue({
el: '#app',
data: {
tabIndex: 0
},
methods:{
enableTab: function(){
console.log("chamou");
var tab = document.getElementById("segundaFase");
tab.removeAttribute('disabled'); }
}
})
</script>
You could set a activeTab in your component data :
data: {
activeTab: 'tab1',
name:'',
email:''
},
then 2 simple methods to set the activetab and return your boolean you will use to render your html :
methods: {
isActiveTab(tabId){
return this.activeTab === tabId
},
setActiveTab(tabId){
this.activeTab = tabId
}
..and a computed for your :disabled property of your button element
computed: {
formIsComplete(){
//here you might want to add some more adequate validation rules
return this.email.length > 0 && this.name.length > 0
}
}
Html side :
<div id="app">
<div class="tab" v-if="isActiveTab('tab1')">
<h2>Tab 1:</h2>
<span> Whatever content you want in tab1</span>
<input v-model="email" type="email"/><label>Email</label>
<input v-model="name" type="text"/><label>Name</label
<button @click="setActiveTab('tab2')" :disabled="!formIsComplete">
Change tab
</button>
</div>
<div class="tab" v-if="isActiveTab('tab2')">
<h2>Tab 2:</h2>
<span> Congrats you made it to Tab2</span>
</div>
</div>
See a simple fiddle here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With