I am thinking how to hold and add a custom handler when empty results are returned while using the server .
At this time there are some questions related to various jQuery plugins (like), but I'm thinking that jQueryUI is to get a better / simpler way with auto completion.
I think this is a common use case, and I thought that jQueryUI has improved the auto-completion of jQuery by adding the ability to handle this situation clearly. Although I can not find documentation of this kind of functionality, and before I remove it, before I saw others before, I will make some feel.
, I can return anything to the server - eg HTTP 204: no content
in a 200 / JSON empty list - which results in auto-completion of jQueryUI Makes the easiest to catch.
My first idea is to pass a callback with two arguments, according to the document, a feedback callback
:
The third change, callback, provides the most flexibility, and may be used to connect to any data source to auto-complete. Callback finds two arguments:
A request object, which has a single property called "term", which is currently in reference to the value in the text input. For example, when the user entered "new yo" in the city area, then the autocomplete word will be equal to the word "new yo."
A response callback, in which an argument is expected to include the data to the user. This data should be filtered based on the given word, and for general local data (with string-array or object-array label / value / both properties), any of the formats described above can be.
When the feedback callback receives no data, it incorporates a special one-line object-array that contains a label and an indicator that there is no data (hence Selection / Focus recognizes this as an indicator that no data was returned).
It seems more complex I want to be able to use a source: "http: // ...", and just point out a callback that no data was back .
Thanks for reading.
Edit:
Here is a cover function that I have created to solve it, @Thif Masters On the basis of the assurance that this is the correct way, go about it:
function auto complete (input, source_value, on_satch, on-focus, default_data) Completion * Input: field to autocomplete * source_url: JSON url data to get * on_select: function (event, ui) - function (event , UI) - When someone selects an element * on_focus: function (Event, UI) - when one focuses one element * default_data: function () Default data is returning; Alternatively * Default dataset eg {'Label': 'x', 'value': 'y'} * / $ (input). Autocomplete ({source: function (request, response) {$ .ajax ({url: source_url, data type: "Jason", data: request, success: work (data) {if ((Data.length!) [] Or var def_data = typeof (default_data) == 'function'? Default_data (): default_data; response (def_data);} and {feedback (data);}}})}}, minnumber: 3, select: on_accounted , Focus: on_focus,}); }
response
automatically overwrite the function of the whole object It can work, but it is the portpatching that is most likely to use feedback callback which you want the best way to achieve.
Comments
Post a Comment