When I select an option, I want to display different types of inputs based on the selected option.
For Example:
- Select
input
-> show input fields - Select
textarea
-> show text areas - Select
boolean
-> show radio buttons
The Code
This is where I choose my input types,
Note: @change="inputType"
<div v-for="(index, a) in variationParents" :key="a">
<el-input placeholder="Please input your variation name" v-model="index.name" class="input-with-select">
<el-select @change="inputType" v-model="index.type" slot="prepend" placeholder="Select">
<el-option label="Text" value="input"></el-option>
<el-option label="Text Area" value="textarea"></el-option>
<el-option label="Boolean" value="boolean"></el-option>
</el-select>
</el-input>
</div>
The Script
Note: I am using jQuery instead of vueJs for this function just to test and make sure that I'm getting the correct value from my select options.
methods: {
inputType: function(value) {
$('.show').html('')
if(value == 'input') {
$('.show').html(value)
} else if(value == 'textarea') {
$('.show').html(value)
} else if(value == 'boolean') {
$('.show').html(value)
}
},
}
The HTML Section
This section should return different types of inputs, currently it only has a static input field. It should be linked to the function's if statements to print the related type of inputs.
<div class="show"></div> // This DIV was used solely for testing my function values
<el-col :span="9" style="margin-top:15px;display:none;">
<div v-for="(indexx, b) in variationChilds" :key="b">
<!-- child's -->
<el-input v-model="indexx.name" placeholder="Please input your variation value" class="input-with-select">
<el-button slot="append" @click="addChild(b)" type="success" icon="el-icon-plus"></el-button>
<el-button slot="append" @click="removeChild(b)" v-show="b || (!b == variationChilds.length > 1)" type="danger" icon="el-icon-delete"></el-button>
</el-input>
</div>
</el-col>
Any thoughts or suggestions?