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 callback function called when user clicks on drop down 'No results found' item #501

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ It expects the returned results from remote API to have a root object. In the ab
| field-required-class | Set custom class name for required. | No | @ | "match" |
| text-searching | Custom string to show when search is in progress. Set this to 'false' prevents text to show up. | No | @ | "Searching for items..." |
| text-no-results | Custom string to show when there is no match. Set this to 'false' prevents text to show up. | No | @ | "Not found" |
| no-result-selected | A callback function called when user clicks on drop down 'No results found' item. | No | = | noResultSelectedFn |
| initial-value | Initial value for component. If string, the internal model is set to the string value, if an object, the title-field attribute is used to parse the correct title for the view, and the internal model is set to the object. [example](https://ghiden.github.io/angucomplete-alt/#example9) | No | = | myInitialValue (object/string) |
| input-changed | A callback function that is called when input field is changed. To get attributes of the input from which the assignment was made, use this.$parent.$index within your function. [example](https://ghiden.github.io/angucomplete-alt/#example10) | No | = | inputChangedFn |
| auto-match | Allows for auto selecting an item if the search text matches a search results attributes exactly. [example](https://ghiden.github.io/angucomplete-alt/#example11) | No | @ | true |
Expand Down
12 changes: 10 additions & 2 deletions angucomplete-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
' <input id="{{id}}_value" name="{{inputName}}" tabindex="{{fieldTabindex}}" ng-class="{\'angucomplete-input-not-empty\': notEmpty}" ng-model="searchStr" ng-disabled="disableInput" type="{{inputType}}" placeholder="{{placeholder}}" maxlength="{{maxlength}}" ng-focus="onFocusHandler()" class="{{inputClass}}" ng-focus="resetHideResults()" ng-blur="hideResults($event)" autocapitalize="off" autocorrect="off" autocomplete="off" ng-change="inputChangeHandler(searchStr)"/>' +
' <div id="{{id}}_dropdown" class="angucomplete-dropdown" ng-show="showDropdown">' +
' <div class="angucomplete-searching" ng-show="searching" ng-bind="textSearching"></div>' +
' <div class="angucomplete-searching" ng-show="!searching && (!results || results.length == 0)" ng-bind="textNoResults"></div>' +
' <div class="angucomplete-searching" ng-show="!searching && (!results || results.length == 0)" ng-bind="textNoResults" ng-click="selectNoResult()"></div>' +
' <div class="angucomplete-row" ng-repeat="result in results" ng-click="selectResult(result)" ng-mouseenter="hoverRow($index)" ng-class="{\'angucomplete-selected-row\': $index == currentIndex}">' +
' <div ng-if="imageField" class="angucomplete-image-holder">' +
' <img ng-if="result.image && result.image != \'\'" ng-src="{{result.image}}" class="angucomplete-image"/>' +
Expand Down Expand Up @@ -704,6 +704,13 @@
clearResults();
};

scope.selectNoResult = function() {
if (typeof scope.noResultSelected === 'function') {
scope.noResultSelected();
clearResults();
}
};

scope.inputChangeHandler = function(str) {
if (str.length < minlength) {
cancelHttpRequest();
Expand Down Expand Up @@ -821,7 +828,8 @@
fieldTabindex: '@',
inputName: '@',
focusFirst: '@',
parseInput: '&'
parseInput: '&',
noResultSelected: '='
},
templateUrl: function(element, attrs) {
return attrs.templateUrl || TEMPLATE_URL;
Expand Down
Loading