jquery - Kendo Autocomplete stopped working if count of found results is null -
i have next autocomplete.
problem if returned result null (no value matched given text input) autocomplete stopped working, means preloader spinner displayed in input , no request created if text changed.
i think problem here don't know homecoming or set if result null:
if(data.results == null) { growlnotifications.add($translate.instant('no_item_found'), 'error', $rootscope.notificationlifetime); homecoming false; } else { options.success(data.results); } here code of method called each time if model value changed (text in autocomplete input).
many advice.
$scope.$watch("teamdetail.newworkername", function(){ console.log($scope.teamdetail.newworkername); $scope.customoptions = { datasource : { type: "json", serverfiltering: true, transport: { read: function (options) { console.log("list"); console.log(options.data); console.log(options.data.filter.filters[0].value); requestparams = { "entityname": "worker", "data" : { "page": 1, "pagesize": 20, "filter": { "logic": "or", "filters": [ { "value": $scope.teamdetail.newworkername, "operator": "contains", "field": "name", "ignorecase": true }, { "value": $scope.teamdetail.newworkername, "operator": "contains", "field": "surname", "ignorecase": true } ] }, "sort": [ { "field": "name", "ord": "asc" } ] } }; apiservice.dohttprequest( "post", $rootscope.apibaseurl + "worker/search", requestparams ) .success(function (data, status, headers, config) { // successful info retrieval console.log("request success, checking state"); console.log(data); // sent status global http status service var jsonresponse = apiservice.processreturnedhttpstate(status); console.log("status response " + jsonresponse.result); // info switch (jsonresponse.result) { case true: if(data.results == null) { growlnotifications.add($translate.instant('no_item_found'), 'error', $rootscope.notificationlifetime); homecoming false; } else { options.success(data.results); } break; case false: growlnotifications.add($translate.instant('list_loading_error'), 'error', $rootscope.notificationlifetime); break; } }) .error(function (data, status, headers, config) { console.log("error"); console.log("autocomplete loading error"); }); } } }, datatextfield: "name", // using templates: template: '#: data.name # #: data.surname #', alter : function (option, data) { console.log("change"); console.log(this.value()); }, select: function(e) { console.log("select"); var item = e.item; var text = item.text(); var index = item.index(); console.log(item); console.log(text); console.log(index); var dataitem = this.dataitem(index); $scope.$apply(function() { $scope.teamdetail.newworkername = text; }); $scope.$apply(function() { $scope.teamdetail.workers.push(dataitem); }); } }; });
kendoui expecting empty array , not null or undefined. can (if cannot alter info returned server) in datasource definition add together schema element , define parse function in case of receiving data null returns [] (and empty array).
something like:
datasource: { transport : { read: ... }, schema : { parse: function(data) { homecoming info ? info : []; } } or can modify code do:
if(data.results == null) { growlnotifications.add($translate.instant('no_item_found'), 'error', $rootscope.notificationlifetime); // homecoming empty array instead of false homecoming op.success([]); } else { options.success(data.results); } jquery angularjs autocomplete kendo-ui
No comments:
Post a Comment