Free text tag lost when selecting other options

10 views
Skip to first unread message

marklar

unread,
Nov 6, 2016, 11:29:47 PM11/6/16
to select2
I've followed a Stackoverflow solution (http://stackoverflow.com/a/30019966/1299792) to update my 3.x project to 4.x and still allow the entry of free text.

I create free text with trailing text of "(new)" to allow the user to know it's a new tag. ie "hello world (new)". I manually set the `value` of this tag so it's saved correctly:

````
var position = dataField.select2("data").length - 1;
dataField[0].selectedOptions[position].value = e.id.toString();
dataField[0].selectedOptions[position].text = e.first_name;
````

This works well for me.

My problem is when I then select an existing option, after `select2:selecting` and before `change`, the free text tag value is removed and it is no longer displayed as selected in the select menu.

Recap of events:
1. Create free text which is now displayed as a selected tag in the select menu
2. Select an existing option
3. After `select2:selecting` before `change`, the free text is removed from dataField.val()

Reply all
Reply to author
Forward
0 new messages