' format no matches' works with json but not ajax data

' 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

  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <link href="js/select2.css" rel="stylesheet"/>
  5.         <meta charset="UTF-8">
  6.         <title>Select2 tests</title>
  7.     </head>
  8.     <body>
  9.         <script src="js/jquery-1.11.1.min.js"></script>
  10.         <script src="js/select2.js"></script>
  11.         <label>Select2 with prepopulated data  (e2)  </label>  
  12.         <input type="hidden" name="optionvalue" id="e2" class="input-xlarge" data-placeholder="Choose An Option.." />  
  13.         <br/>
  14.         <label>Select2 with Ajax data  (e3)   </label>  
  15.         <input type="hidden" name="optionvalue" id="e3" class="input-xlarge" data-placeholder="Choose An Option.." />  
  16.         <br/>

  17.         <script>
  18.                    var a = [{"id": "15", "text": "arc"}, {"id": "18", "text": "cat"}, {"id": "12", "text": "con"}];
  19.             $('#e2').select2({
  20.                 data: a,
  21.                 formatNoMatches: function (term) {
  22.                     alert("No Matches in E2 box");
  23.                 },
  24.             });
  25.             $('#e3').select2({
  26.                 // minimumInputLength: 2,
  27.                 // tags:true,
  28.                 // multiple: true,
  29.                 formatNoMatches: function (term) {
  30.                     alert("No Matches E3 box");
  31.                 },
  32.                 ajax: {
  33.                     url: 'functions.php',
  34.                     dataType: 'json',
  35.                     data: function (term, page) {
  36.                         return {
  37.                             q: term
  38.                         };
  39.                     },
  40.                     results: function (data, page) {
  41.                         return {results: data};
  42.                     }
  43.                 },
  44.             });
  45.            
  46.         </script>
  47.     </body>
  48. </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