You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

np-autocomplete

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

np-autocomplete

Full-functional autocomplete (typeahead alternative) AngularJS directive

2.1.1
latest
Source
npm
Version published
Weekly downloads
505
-0.98%
Maintainers
1
Weekly downloads
 
Created
Source

Np-autocomplete

Np-autocomplete is a full-functional autocomplete (typeahead alternative) AngularJS directive.

Key Features:

  • The easiest to setup.
  • 100% compatible and optimised by default for bootstrap 3.3.5+
  • Provides 4 models: ngModel, npInputModel, npAuto and selectedItem.
  • You are free to use built-in angular directives such ngForm and ngRequired.
  • Uses the transclusion, which gives the flexibility with the input element.
  • Customizable in the way you like.
  • Multiple states (close, open, load and error).

Requirements:

  • JQuery 2.1.4+.
  • AngularJS 1.3.16+.
  • Bootstrap 3.3.5+ (for default template).

Getting Started:

Download the package, then include dist/np-autocomplete.min.js and dist/np-autocomplete.min.css in your page.

bower install np-autocomplete --save

Now, add it to your angular module dependencies list as the following:

angular.module('yourModule', [
  'ng-pros.directive.autocomplete',
  ...
]);

Note: if you were using version 1.0.x then refer to CHANGELOG.

Quick Usage:

html:
<div class="form-group" np-autocomplete="npAutocompleteOptions" ng-model="repoID">
  <label class="control-label">Repository</label>
  <input class="form-control" type="text"/>
</div>
js:
myAngularApp.controller('ctrl', ['$scope', function($scope) {
  $scope.npAutocompleteOptions = {
    url: 'https://api.github.com/search/repositories'
  };
}]);

You can also see the demos.

Attributes:

AttributeRequiredDescription
np-autocompleteYesPasses options object to the directive.
ng-modelNoHolds the value of an attribute of the selected item, e.g. "id".
np-input-modelNoHolds the input element value.
np-selected-itemNoHolds the whole selected item object.
np-autoNoA model which by updating it the following will happen: update np-input-model with its value, clear ng-model, make a request then flushes itself.

Options:

AttributeTypeRequiredDefault ValueExampleDescription
urlStringYeshttp://example.comData source url.
nameAttrStringNonamefull_nameDefines the attribute which will be shown in the list (usually, it is the search field).
valueAttrStringNoiddownloads_urlDefines the attribute which will be assigned to the ng-model attribute.
limitIntegerNo510Sets the value of the limit query param.
limitParamStringNolimitper_pageQuery param holds the limit value in requests.
searchParamStringNosearchqueryQuery param holds the search text in requests.
queryModeBooleanNotruefalseDetermines if the searchParam will be in query mode or param mode, in case it has been set to false (param mode) then you should include :searchParam string in your url where the search value goes.
delayIntegerNo500 (ms)1000 (ms)Time in milliseconds which delays request after changing the search text.
minlengthIntegerNo15The minimum length of string required before start searching.
dataHoderStringNoitemsThe name of the field in the retrieved data which holds the array of objects those will be used for the autocomplete.
clearOnSelectBooleanNofalsetrueEither clear the search text after selecting an item or not.
highlightExactSearchBooleanNotruefalseeither highlight with exact pattern or each portion separately.
templateString (HTML)NoOverrides the default template.
templateUrlStringNoGets template with $templateCache to overrides the default template.
itemTemplateString (HTML)NoOverrides the default template of the list item.
itemTemplateUrlStringNoGets template with $templateCache to overrides the default template of the list item.
paramsObjectNo{ sort: 'stars' }Extra params to send with each request.
errorMessageStringNoSomething went wrong.An error occurred.A message to be shown when an error occur.
noResultsMessageStringNoNo results found.Couldn't find anything.A message to be shown when no results found.
listClassStringNolist-grouplist-group np-listClass(es) to be added to the list.
itemClassStringNolist-group-itemlist-group-item np-list-itemClass(es) to be added to each item in the list.
messageClassStringNolist-group-itemlist-group-item np-message-itemClass(es) to be added to each message item.
highlightClassStringNobg-info text-infonp-highlightClass(es) to be added to the highlighted text.
itemFocusClassStringNoactivenp-activeClass(es) to be added to the focused item.
hasSelectionClassStringNonp-autocomplete-has-selectionhas-selectionClass(es) to be added to the directive wrapper when a selection made.
openStateClassStringNonp-autocomplete-opennp-autocomplete-open open-stateClass(es) to be added to the directive wrapper in 'open' state.
loadStateClassStringNonp-autocomplete-loadnp-autocomplete-load load-stateClass(es) to be added to the directive wrapper in 'load' state.
closeStateClassStringNonp-autocomplete-closenp-autocomplete-close close-stateClass(es) to be added to the directive wrapper in 'closed' state.
errorStateClassStringNonp-autocomplete-errornp-autocomplete-error error-stateClass(es) to be added to the directive wrapper in 'load' state.
eachFunctionNofunction(item) {
console.log(item);
}
Iterates over elements of retrived data.
onBlurFunctionNofunction() {
console.log('focus lost');
}
a callback function called when the directive loses focus.
onErrorFunctionNofunction(errorData) {
console.log(errorData);
}
A callback function called when an error occur.
onSelectFunctionNofunction(item) {
console.log(item);
}
A callback function called when a selection is made.
onDeselectFunctionNofunction() {
console.log('Lost selection');
}
A callback function called when the selection is lost.

Keywords

autocomplete

FAQs

Package last updated on 31 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts