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 pleted 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 modo 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>
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 pleted 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 modo 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>
Share
Improve this question
edited Sep 16, 2018 at 11:04
Arend
3,7722 gold badges28 silver badges38 bronze badges
asked Sep 15, 2018 at 23:21
Carolina de MoraesCarolina de Moraes
572 silver badges8 bronze badges
0
3 Answers
Reset to default 4You could set a activeTab
in your ponent 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 puted for your :disabled
property of your button element
puted: {
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
Assign your attribute to a reactive data member
<b-tab id="segundaFase" title="Segunda Fase" :disabled=‘disabled’ >
data: {disabled:true}
In your click handler, mutate the data
onClick(){ this.disabled=!this.disabled}
You can achieve this option with another way by using the disabled property of a tab I will introduce some code below and explain
<div id="app">
<b-tabs>
<b-tab title="first" active>
<br>I'm the first tab
<button v-on:click="enableThirdTab">Enable third tab</button>
</b-tab>
<b-tab title="second">
<br>I'm the second tab
</b-tab>
<b-tab title="third" v-bind:disabled="tabDisabled">
<br>Im the third tab
</b-tab>
</b-tabs>
</div>
new Vue({
el:'#app',
data:function(){
return {
tabDisabled:true
}
},
methods:{
enableThirdTab:function(){
this.tabDisabled = false;
}
}
});
You can use the property disabled
of the b-tab to enable or disable it programmitcally
So in your data function create a property tabDisabled
with true as first state and bind it to the tab as v-bind:disabled="tabDisabled"
Then you can have the method in methods:{} enableTab where all you need to do is to set this.tabDisabled = false;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744308905a4567853.html
评论列表(0条)