I am using Select2 for making a dropdown and using the dropdown to run a particular code for a particular option.
Initialised my select2 with the 3 options:
$("#tags").select2({tags:["name", "job_title", "gender"]});
Now here is my function:
_get_employee_data: function(events){
console.log(events.target.value);
this._rpc({
route: '/get/parent/employee_new',
}).then(function (result) {
tags = $('#tags').val();
if (tags=="name"){
console.log(tags);
//$('#_name').empty();
$('#_name').append(result['name']);
}
else if(tags=="job_title") {
//$('#_job_title').empty();
$('#_job_title').append(result['job_title']);
}
else if(tags=="gender"){
//$('#hello').empty();
$('#_gender').append(result['gender']);
}
})
Now, when I select only name it ll show the names. When I select job_title and remove the previous name tag, it ll show the names and job_titles(good). But if I select 2 or multiple options and click submit it won't work. I ll have to remove the previous tag name or gender and enter only one value to use the function.
How can I select multiple options??
One way is obviously using If Else for all my conditions but it's not feasible since the tags are around 5-10 so won't be really possible to use if-else for all variations.
Any help is appreciated. Thanks.
For some reason Can't use select2 above 4.0, causing issues with the whole setup so need alternative. Still if there is a way using Select2>4.0 that would be appreciated as well.