Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added event requestfailed #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ TinyAutocomplete won't instantiate again, it will just change the settings on th

## Events

Tiny Autocomplete fires some events for you to hook into. The only ones implemented right now are `beforerequest` and `receivedata`. You can use them to maybe show a spinner somewhere else or something like that, but the `receivedata` event is useful for massaging the data you get back from your server, too. If your json is structured a little differently than expected, perhaps something like this:
Tiny Autocomplete fires some events for you to hook into. The only ones implemented right now are `beforerequest`, `requestfailed` and `receivedata`. You can use them to maybe show a spinner somewhere else or something like that, but the `receivedata` event is useful for massaging the data you get back from your server, too. If your json is structured a little differently than expected, perhaps something like this:

```javascript
{
Expand Down Expand Up @@ -325,6 +325,8 @@ $(".field")
});
```

You can also hook into the `requestfailed` event if you for example wants to notify the user that an error has occured.

## License

[MIT](http://johanhalse.mit-license.org)
26 changes: 14 additions & 12 deletions src/tiny-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,20 @@ var factory = function($, window) {
* @param {string} val Value to search for
* @return {null}
*/
remoteRequest: function(val) {
this.field.trigger("beforerequest", [this, val]);
var data = {};
$.extend(data, this.settings.queryParameters);
data[this.settings.queryProperty] = val;
$.ajax({
method: this.settings.method,
url: this.settings.url,
dataType: "json",
data: data,
success: $.proxy(this.beforeReceiveData, this)
});
remoteRequest: function (val) {
var self = this;
this.field.trigger("beforerequest", [this, val]);
var data = {};
$.extend(data, this.settings.queryParameters);
data[this.settings.queryProperty] = val;
$.ajax({
method: this.settings.method,
url: this.settings.url,
dataType: "json",
data: data,
success: $.proxy(this.beforeReceiveData, this),
error: function () { self.field.trigger("requestfailed", [self, val]); }
});
},

/**
Expand Down