' format no matches' works with json but not ajax data
Hi
If my select2 is populated with json and no matches are found works with format no matches. However if I my data is populated by ajax I am not notified in any way that no matches are found. There is nothing I can hook into to take appropriate action
- <!DOCTYPE html>
- <html>
- <head>
- <link href="js/select2.css" rel="stylesheet"/>
- <meta charset="UTF-8">
- <title>Select2 tests</title>
- </head>
- <body>
- <script src="js/jquery-1.11.1.min.js"></script>
- <script src="js/select2.js"></script>
- <label>Select2 with prepopulated data (e2) </label>
- <input type="hidden" name="optionvalue" id="e2" class="input-xlarge" data-placeholder="Choose An Option.." />
- <br/>
- <label>Select2 with Ajax data (e3) </label>
- <input type="hidden" name="optionvalue" id="e3" class="input-xlarge" data-placeholder="Choose An Option.." />
- <br/>
-
- <script>
- var a = [{"id": "15", "text": "arc"}, {"id": "18", "text": "cat"}, {"id": "12", "text": "con"}];
- $('#e2').select2({
- data: a,
- formatNoMatches: function (term) {
- alert("No Matches in E2 box");
- },
- });
- $('#e3').select2({
- // minimumInputLength: 2,
- // tags:true,
- // multiple: true,
- formatNoMatches: function (term) {
- alert("No Matches E3 box");
- },
- ajax: {
- url: 'functions.php',
- dataType: 'json',
- data: function (term, page) {
- return {
- q: term
- };
- },
- results: function (data, page) {
- return {results: data};
- }
- },
- });
-
- </script>
- </body>
- </html>
In the e3 select2 the alter box is never shown indicating the function is never called so I cannot respond when there are no matches
Many thanks