PUGX / PUGXAutoCompleterBundle

Add an autocomplete field to your Symfony forms
GNU Lesser General Public License v3.0
93 stars 38 forks source link

[with jquery-ui] create a "response" callback function #61

Closed maathieu closed 4 years ago

maathieu commented 4 years ago

Hello (again again),

There is a nice undocumented feature in your code (please document it!) allowing to add a javascript callback from the webpage's app.js code by setting parameter on_select_callback.

In my project I have had the need to add a function that is called when the "response" event is fired (this event is fired after the search request is complete, cf here ).

I added the following code to autocompleter-jqueryui.js to allow my code to hook a function to this event, by adding this:

// inside var settings = { ...
  on_response_callback: null // default setting, function does not do anything

// after the end of select: function (event, ui) {... },
response: function (event, ui) {
 if (settings.on_response_callback) {
  settings.on_response_callback($this, event, ui);
 }
}

It then becomes possible to add a response callback in app.js like this:

$('#mysearch').autocompleter({
 url_list: '/some-search',
 url_get: '/some-get/',
 min_length: 4,
 on_response_callback: function (autocompleteInstance, event, ui) { ... },
})

Many thanks in advance,

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue is closed because was marked as stale and had no activity. Thank you for your contributions.