diff --git a/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee b/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee index 9c3da1044..1176c69cb 100644 --- a/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee +++ b/app/assets/javascripts/app/lib/app_post/z_searchable_ajax_select.coffee @@ -13,11 +13,11 @@ class App.SearchableAjaxSelect extends App.SearchableSelect # create cache and cache key @searchResultCache = @searchResultCache || {} - @cacheKey = "#{objectString}+#{@query}" + cacheKey = "#{objectString}+#{@query}" # use cache for search result - if @searchResultCache[@cacheKey] - return @onAjaxResponse( @searchResultCache[@cacheKey] ) + if @searchResultCache[cacheKey] + return @renderResponse( @searchResultCache[cacheKey] ) # add timeout for loader icon clearTimeout @loaderTimeoutId @@ -32,18 +32,18 @@ class App.SearchableAjaxSelect extends App.SearchableSelect query: @query limit: @options.attribute.limit processData: true - success: @onAjaxResponse + success: (data, status, xhr) => + # cache search result + @searchResultCache[cacheKey] = data + + @renderResponse(data) ) - onAjaxResponse: (data, status, xhr) => - + renderResponse: (data) => # clear timout and remove loader icon clearTimeout @loaderTimeoutId @el.removeClass('is-loading') - # cache search result - @searchResultCache[@cacheKey] = data - # load assets App.Collection.loadAssets(data.assets)