jquery-select2

Select2 doesn't show selected value

笑着哭i 提交于 2019-11-28 06:15:24
Select2 loads all items from my list successful, the issue I found when try to select a specific value when page loads. Example: :: put select2 in a specific html element, no value is selected even all items are loaded. $('#my_id').select2(); :: When the page is loaded I'm trying to show a specific item selected, but doesn't work as expected, because even selected, the select2 doesn't show it. $('#my_id').val('3'); //select the right option, but doesn't render it on page loads. How to make a selected option to pop up when pages loads? Thanks in advance. UPDATED :: How I load all select2 items

Is it possible to paste a list to a select2 field and match each item in the list?

眉间皱痕 提交于 2019-11-28 06:01:28
I am using Select2 to manage large lists of data. Users have expressed a desire to be able to paste a list to the Select2 field in order to select various items at once instead of manually entering and matching each item in the list. I have attempted to use tokenSeparators to separate the items in the list. This and the demo on tokens in the documentation lead me to believe that what I am hoping to do is possible, but so far I have had no joy. The code I use to instantiate Select2 is: $('input').select2({ width: 'element', matcher: function (term, text) { return text.toUpperCase().indexOf(term

How to automatically increase the height of select2 input box (multiple)

ぐ巨炮叔叔 提交于 2019-11-28 05:30:20
问题 I have a select2 input box for multiselet option in which, user can select as many options as he wants, if the selected options are occupying more space than available width then I wanted to increase the height of the select box automatically (don't want scroll option, all options should be in viewable space) and get the remaining options in next line. Currently options are coming in the next line but the height of the select box is not increased. If I remove the height property in the

Select2 start with input field instead of dropdown

跟風遠走 提交于 2019-11-28 05:18:40
I use the js library select2 . This is a screenshot of what I have now: Start: Click on dropdown: Now is it possible to have an input field to start with and not directly a dropdownlist? I know it's possible because you can find it on the select2 site. An example is this: But the documentation is very brief. This is what I have now: <input type="text" name="questions[question1]" id="question1" class="question1" style="width:500px"/> function createQuestionTags(data, question_number){ $(".question" + question_number).select2({ createSearchChoice: function (term, data) { if ($(data).filter

Select2 Dropdown autoselect if only 1 option available

喜你入骨 提交于 2019-11-28 05:00:23
问题 I have a select2 dropdown box using remote datasource. What I would like to do is if/when there is only one option returned by the search, auto select it. ie, the user doesn;t have to click on the option to make the selection. $("#searchInfo_Entity_Key").select2({ ajax: { url: "/Adjustment/GetEntity", dataType: 'json', delay: 250, data: function (params) { return { term: params.term, // search term }; }, processResults: function (data) { return { results: data }; }, results: function (data) {

Trigger an action after selection select2

£可爱£侵袭症+ 提交于 2019-11-28 04:03:28
I am using select2 library for my search. is there any way to trigger an action after selecting a search result? e.g. open a popup, or a simple js alert. $("#e6").select2({ placeholder: "Enter an item id please", minimumInputLength: 1, ajax: { // instead of writing the function to execute the request we use Select2's convenient helper url: "index.php?r=sia/searchresults", dataType: 'jsonp', quietMillis: 3000, data: function (term, page) { return { q: term, // search term page_limit: 10, id: 10 }; }, results: function (data, page) { // parse the results into the format expected by Select2. //

jQuery select2 get value of select tag?

ぐ巨炮叔叔 提交于 2019-11-28 04:02:20
Hello friends this is my code: <select id='first'> <option value='1'> First </option> <option value='2'> Second </option> <option value='3'> Three </option> </select> This is my select2 code: $("#first").select2(); Below is code for getting selected value. $("#first").select2('val'); // It returns first,second,three. This is return a text like first,second,three and I want to get 1,2,3 . Means I need the value of select box, not text. $("#first").val(); // this will give you value of selected element. i.e. 1,2,3. To get Select element you can use $('#first').val(); To get the text of selected

Tagging with AJAX in select2

ⅰ亾dé卋堺 提交于 2019-11-28 02:48:58
I am doing tagging with select2 I have these requirements with select2: I need to search some tags using select2 ajax Also I need to use "tags" in select2 which Allows values that are not in the list(Ajax result). Both the scenarios work independently. But joined together aJax values are only populated. If we type any other values not in the list then it says "no matches found" My scenario If user type any new value which is not in the list, allow them to make up their own tag. Any way to make this work? Select2 has the function "createSearchChoice": Creates a new selectable choice from user's

Jquery select2 json data with optgroup and images

泪湿孤枕 提交于 2019-11-27 23:03:03
问题 I am using select2 with spring mvc. I got the data from my controller that I need to display here in terms of options. But I want them to be grouped as optgroup and also I want images to be appended in it which can be inserted manually as given below : - <optgroup label="group"> <option value="imageName">value 1</option> <option value="imageName">value 1</option> </optgroup> Where imageName is the name of image. I want to : 1) Group options in json. 2) Provide this image attribute in json so

Select2: How to prevent tags sorting

流过昼夜 提交于 2019-11-27 22:15:44
When user selects many items (tags), they are automatically sorted alphabetically. How to prevent automatic sort and keep user's order using Select2 4.0? Update: The mentioned "possible dublicate question" is for the older version of Select2 v3... I ask about version 4... It differs form older ones and mentioned answers dosn't solve the problem. I've found a solution that works with Select2 v4. It changes the order of items - item selected by user are moved to the end. $("select").select2(); $("select").on("select2:select", function (evt) { var element = evt.params.data.element; var $element =