Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>source</code> option definitely need not be static. In fact, I think that's mainly what is wrong with your declaration of the widget and specification of the options. It looks like you are using <code>GradTax.cfc</code> as your dynamic source. So you need to set your <code>source</code> option to be a function which calls your dynamic source via AJAX. On AJAX success inside the <code>source</code> option, you call the <code>response</code> callback provided in the declaration <code>source: function(request, response)</code>. That function signature is specified by jQuery as what is required if you are going to have a function providing dynamic results. In that case, <code>request</code> contains information about the current input in the autocomplete box that you can use (you use <code>request.term</code> to pass through <em>what</em> to autocomplete, and <code>response</code> represents the callback function that will get called once your AJAX function completes. See more in the <a href="http://api.jqueryui.com/autocomplete/#option-source" rel="nofollow">jQuery UI documentation</a>.</p> <p>You can search for the <code>source</code> option to see pretty much the same info I provided above. What you need to do (or close to it at least) is (not tested by the way): </p> <pre><code>jQuery( document ).ready(function($) { $("#CollegeName").autocomplete({ source: function (request, response) { $.ajax({ type: 'Get', url: '/services/GradTax.cfc?method=GetSchoolsJson&amp;returnformat=json', data: {searchPhrase: request.term}, dataType: 'json', error: function(xhr, textStatus, errorThrown) { // show error alert(errorThrown) }, success: function(result) { response(result); //Need to make sure result is an array of objects at // least containing the necessary properties used by // jQuery autocompleter. Each object should, I believe, // contain a 'label' and a 'value' property. See docs for an example: // http://jqueryui.com/autocomplete/#remote-jsonp } }); }, minLength: 3, select: function(event, ui) { $('#company_id').val(ui.item.id); //this should take care of what needs to happen when you actually click / select one of the items that was autocompleted. See documentation above and search for the 'select' option for usage. } }); }); </code></pre> <p>Referring to the <a href="http://jqueryui.com/autocomplete/#remote-jsonp" rel="nofollow">jQuery remote jsonp data source Demo</a>, note that in the AJAX success callback above, the response from the AJAX call does not <em>need</em> to be an array of objects containing a <code>value</code> and a <code>label</code> property, but the object that gets passed in to the <code>response</code> callback does need to have those. That's exactly how the jQuery demo works. They manually <code>$.map</code> the response to be an array of objects containing <code>value</code> and <code>label</code> based on their ajax response. <code>label</code> is what is actually displayed in the interface of the autocompleter, i.e. what the user would see, whereas <code>value</code> is what is set to the original input's value. Note in their example above that <code>value</code> is also used in the <code>select</code> option. Not the most straightforward thing in the world but when you see what is going on it's not too bad to work with! </p> <p>Here it is working in <a href="http://jsfiddle.net/sbCwb/1/" rel="nofollow">JSFiddle</a>. That will get a 404 since the autocomplete endpoint won't be found, but you'll see if you watch developer tools that the text to be autocompleted is passed along in the query string (you'll get alerted saying there was an error), it's a basic proof-of-concept.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload