jquery-select2

Reset select2 value and show placeholder

好久不见. 提交于 2019-11-27 03:01:52
How do I set the placeholder on value reset by select2. In my example If locations or grade select boxes are clicked and my select2 has a value than the value of select2 should reset and show the default placeholder. This script is resetting the value but won't show the placeholder $("#locations, #grade ").change(function() { $('#e6').select2('data', { placeholder: "Studiengang wählen", id: null, text: '' }); }); $("#e6").select2({ placeholder: "Studiengang wählen", width: 'resolve', id: function(e) { return e.subject; }, minimumInputLength: 2, ajax: { url: "index.php?option=com_unis&task

Trigger an action after selection select2

China☆狼群 提交于 2019-11-27 00:12:41
问题 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:

Update select2 data without rebuilding the control

本小妞迷上赌 提交于 2019-11-26 23:02:56
I am converting an <input type="hidden"> to a select2 dropdown and feeding it data through the query method $('#inputhidden').select2({ query: function( query ) { query.callback( data ); // the data is in the format select2 expects and all works well.. ); }); The problem is i needed to hack the select2 UI and position two buttons on top of the search bar that, when clicked, will perform ajax calls and will have to update the select2 content. Now, I need those updates to occur without rebuilding the select2 entirely but rather just refreshing the items on the dropdown. I cannot find a way to

Clear dropdown using jQuery Select2

偶尔善良 提交于 2019-11-26 22:36:36
I'm trying to programmatically clear a drop down using the fantastic Select2 library. The drop down is dynamically filled with a remote ajax call using the Select2 query option. HTML: <input id="remote" type="hidden" data-placeholder="Choose Something" /> Javascript: var $remote = $('#remote'); $remote.select2({ allowClear: true, minimumInputLength: 2, query: function(options){ $.ajax({ dataType: 'json', url: myURL + options.term, error: function(jqXHR, textStatus, errorThrown){ smoke.alert(textStatus + ": server returned error on parsing arguments starting with " + options.term); }, success:

“query function not defined for Select2 undefined error”

笑着哭i 提交于 2019-11-26 21:46:23
Trying to use Select2 and getting this error on multiple item input/text field: "query function not defined for Select2 undefined error" Covered in this google group thread The problem was because of the extra div that was being added by the select2. Select2 had added new div with class "select2-container form-select" to wrap the select created. So the next time i loaded the function, the error was being thrown as select2 was being attached to the div element. I changed my selector... Prefix select2 css identifier with specific tag name "select": $('select.form-select').select2(); This error

Select2 v4 how to paginate results using AJAX

放肆的年华 提交于 2019-11-26 20:35:40
问题 I'm trying to paginate results (every 25 rows) using Select2 4.0, but I don't know how to achieve it. Does somebody know how to do it? If the user reach the end of the 25 rows and if there is more rows I would like to load it and show it. Here is my HTML template <div class="form-group"> {!! Form::select('breed_id', $breeds, null, ['class' => 'form-control', 'id' =>'breed_id'] ) !!} </div> And here is the JavaScript for Select2. $("#breed_id").select2({ placeholder: 'Breed...', width: '350px'

How to make select2 work with jquery.validation plugin?

旧街凉风 提交于 2019-11-26 19:24:15
问题 I'm trying to validate select2 field using jquey.validation plugin but nothing happens. I want to make select required field. I'm using this custom validation function: $.validator.addMethod("requiredcountry", function(value, element, arg){ return arg != value; }, "Value must not equal arg."); and this is the rule: rules: { country: { required: true, requiredcountry: "" } } What select2 field should I use for the rule to match? I appreciate any idea how to make select2 working together with

JQuery select2 set default value from an option in list?

五迷三道 提交于 2019-11-26 19:14:06
问题 I want to be able to set the default/selected value of a select element using the JQuery Select2 plugin. 回答1: One more way - just add a selected = "selected" attribute to the select markup and call select2 on it. It must take your selected value. No need for extra JavaScript. Like this : Markup <select class="select2"> <option id="foo">Some Text</option> <option id="bar" selected="selected">Other Text</option> </select> JavaScript $('select').select2(); //oh yes just this! See fiddle : http:/

Select2 Ajax Method Not Selecting

柔情痞子 提交于 2019-11-26 19:07:58
问题 Ok, I'm sure there's something simple set wrong here but I'm not 100% what it is. So I am trying to use Select2 AJAX method as a way of users to search a database and select a result. The call itself is coming back with results, however it will not allow me to select the answer from the list. It also doesn't seem to allow you to "select" it on hover or up/ down arrow. So without further ado, here is my code: index.html <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9

Selectable optgroup using select2

吃可爱长大的小学妹 提交于 2019-11-26 18:14:57
问题 I have used select2 to select multiple options from a drop down, but is it possible for select2 to select the full optgroup?? What I want is when user select the option group all the child options should be selected. And I want to do this using jQuery Select2 . How could I do this? 回答1: This is possible if you back the Select2 with a hidden input element -- instead of a select element. To make a group option selectable, you must give it an "id", but it appears it can be an empty string. You