Skip to content

Commit

Permalink
fix(dropdown): support callbacks given inside apisettings
Browse files Browse the repository at this point in the history
Whenever a dropdown had apiSettings set which also contained any callback for onSuccess or onFailure or onError, the menu was not shown anymore.
The search component had the same issue, so i also fixed it there.
  • Loading branch information
lubber-de authored Jul 16, 2022
1 parent 8d87844 commit f49946a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,20 +814,28 @@ $.fn.dropdown = function(parameters) {
throttle : settings.throttle,
urlData : {
query: query
},
onError: function() {
}
},
apiCallbacks = {
onError: function(errorMessage, $module, xhr) {
module.add.message(message.serverError);
iconClicked = false;
focused = false;
callback.apply(null, callbackParameters);
if(typeof settings.apiSettings.onError === 'function') {
settings.apiSettings.onError.call(this, errorMessage, $module, xhr);
}
},
onFailure: function() {
onFailure: function(response, $module, xhr) {
module.add.message(message.serverError);
iconClicked = false;
focused = false;
callback.apply(null, callbackParameters);
if(typeof settings.apiSettings.onFailure === 'function') {
settings.apiSettings.onFailure.call(this, response, $module, xhr);
}
},
onSuccess : function(response) {
onSuccess : function(response, $module, xhr) {
var
values = response[fields.remoteValues]
;
Expand All @@ -852,13 +860,16 @@ $.fn.dropdown = function(parameters) {
iconClicked = false;
focused = false;
callback.apply(null, callbackParameters);
if(typeof settings.apiSettings.onSuccess === 'function') {
settings.apiSettings.onSuccess.call(this, response, $module, xhr);
}
}
}
;
if( !$module.api('get request') ) {
module.setup.api();
}
apiSettings = $.extend(true, {}, apiSettings, settings.apiSettings);
apiSettings = $.extend(true, {}, apiSettings, settings.apiSettings, apiCallbacks);
$module
.api('setting', apiSettings)
.api('query')
Expand Down
26 changes: 21 additions & 5 deletions src/definitions/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,36 @@ $.fn.search = function(parameters) {
urlData : {
query : searchTerm
},
onSuccess : function(response) {
},
apiCallbacks = {
onSuccess : function(response, $module, xhr) {
module.parse.response.call(element, response, searchTerm);
callback();
if(settings.apiSettings && typeof settings.apiSettings.onSuccess === 'function') {
settings.apiSettings.onSuccess.call(this, response, $module, xhr);
}
},
onFailure : function() {
onFailure : function(response, $module, xhr) {
module.displayMessage(error.serverError);
callback();
if(settings.apiSettings && typeof settings.apiSettings.onFailure === 'function') {
settings.apiSettings.onFailure.call(this, response, $module, xhr);
}
},
onAbort : function(response) {
onAbort : function(status, $module, xhr) {
if(settings.apiSettings && typeof settings.apiSettings.onAbort === 'function') {
settings.apiSettings.onAbort.call(this, status, $module, xhr);
}
},
onError : module.error
onError : function(errorMessage, $module, xhr){
module.error();
if(settings.apiSettings && typeof settings.apiSettings.onError === 'function') {
settings.apiSettings.onError.call(this, errorMessage, $module, xhr);
}
}
}
;
$.extend(true, apiSettings, settings.apiSettings);
$.extend(true, apiSettings, settings.apiSettings, apiCallbacks);
module.verbose('Setting up API request', apiSettings);
$module.api(apiSettings);
}
Expand Down

0 comments on commit f49946a

Please sign in to comment.