2

How to add few options as selected I am using this plugin: https://github.com/selectize/selectize.js/blob/master/docs/usage.md

I have an object like shown in below image: enter image description here

This my my CLient script

//skills
$scope.$selectSkill = $('#selectSkill').selectize({
    valueField: 'id',
    labelField: 'name',
    searchField: 'name',
    placeholder: "Select Skills",
    options: $scope.data.skills,
    create: false,
    sortField: {
        field: 'name',
        direction: 'asc'
    }
});

This is my HTML

<select id="selectSkill" 
name="selectSkill" 
ng-model="selectSkill" 
multiple required> </select>

and this how it's loading so far everything is good, enter image description here

Now when i trigger a method i will get some(two) values like this in response:

48c9eda9c0a8018b4b6aca082d5d1e41  ,  48c9fe9ac0a8018b6a37e4db0d07df09

I want these two get selected as shown in below image enter image description here

How can I do it..?

I have tried something like this:

var $select = $("#selectSkill").selectize();
                var yourDefaultIds = [slectedSkills.skills];  //(those 2 vlaues)
                selectize.setValue(yourDefaultIds);;

1 Answer 1

4
//populate skills starts here
var templateSkills = finTempObj.skills;
var str_array_skills = templateSkills.split(',');
var $select =   $("#selectSkill").selectize();
var selectize = $select[0].selectize;
selectize.setValue(str_array_skills);
selectize.refreshOptions();
//populate skills ends here

This should work I have tested it. instead of setting as string convert those two values as an array then set.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.