Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit bbf6077

Browse files
committed
updated doc and info npm
1 parent e2a8106 commit bbf6077

3 files changed

Lines changed: 10 additions & 255 deletions

File tree

README.md

Lines changed: 5 additions & 250 deletions
Original file line numberDiff line numberDiff line change
@@ -1,256 +1,11 @@
11
angucomplete-alt
22
============
3+
This project is a fork of ghiden https://github.com/ghiden/angucomplete-alt, to add feature to control either the initialValue is listener canceled or not by attr keepBindInitialValue.
34

4-
This is a fork of Daryl Rowland's angucomplete (https://github.com/darylrowland/angucomplete) with a bit of tweaks such as:
5+
* To more info about angucomplete-alt see https://github.com/ghiden/angucomplete-alt.
56

6-
* change long attribute names to hyphenated ones
7-
* coding style similar to angular standard
8-
* refactored in general
9-
* jshint
10-
* more test coverage
7+
This repository is alive until the pull request be accepeted on master of angucomplete-alt.
118

12-
To see a demo go here: https://ghiden.github.io/angucomplete-alt
13-
14-
###Key Features
15-
* Show just a title, a title and a description or a title, description and image in your autocomplete list
16-
* Deliberately minimally styled so you can customise it to your heart's content!
17-
* Reads JSON data and allows you to specify which fields to use for display
18-
* Simple setup - e.g. to pull data from a server, just set the url parameter
19-
20-
### Extra Features
21-
* Request format function: if you need to tweak data before you send to your search API, you can set your own format function. Search query goes through your function and gets sent to your API.
22-
* Response format function: if you need to tweak response from the server before it gets processed by the directive, you can set your own format function. Raw HTTP response goes through your function. Thanks to @nekcih for proposing this feature.
23-
* Clear on selection: when you select an item, input field is cleared.
24-
* Blur event handling, thanks to @leejsinclair
25-
* Override suggestions
26-
* You can either bind an object or callback function
27-
* bind an object: it works as one-way-data-binding. It gets set when a selection is made.
28-
* callback function: when a selection is made by user, this callback is called with the selected object. When the selection is deselected, the callback is called with undefined. Thanks to @nekcih for proposing this feature.
29-
* Required support: It is a bit different from ng-required which becomes valid when there is any character in input field. This required becomes valid when a selection is made. Class name is "autocomplete-required" and customizable. Thanks to @alindber for the initial idea.
30-
* Custom texts for "Searching..." and "No results found", thanks to @vhuerta for this idea.
31-
* Be able to set initial value. This becomes handy if you use this directive for updating existing model.
32-
* Be able to set a error callback for ajax request
33-
* Add a callback for tracking input changes. Thanks to @urecio for the initial idea.
34-
* Auto match
35-
* Add callbacks for tracking focus in/out.
36-
* Enable/disable input field
37-
* Show scrollbar. See [example #1](https://ghiden.github.io/angucomplete-alt/#example1)
38-
* Clear input by sending $broadcast from parent scope. Thanks to @Leocrest for #61.
39-
* Override template with your own. When you use this feature, test throughly as it might break other features. Thanks to @sdbondi for #74.
40-
* Show all items.
41-
* Custom remote API handler which allows you to fully control how to communicate with your remote API. Thanks to @jbuquet
42-
* Custom search function for handling local data
43-
44-
### Angular 1.2
45-
46-
From v2.0.0, I have dropped the support for angular 1.2.
47-
Please use [angucomplete-ie8](https://github.com/ghiden/angucomplete-ie8) which still supports 1.2.
48-
49-
### Getting Started
50-
Download the package, and include the dist/angucomplete-alt.min.js file in your page.
51-
52-
```bash
53-
bower install angucomplete-alt --save
54-
```
55-
56-
Or
57-
58-
```bash
59-
npm install angucomplete-alt --save
60-
```
61-
62-
Then add the angucomplete-alt module to your Angular App file, e.g.
63-
64-
```js
65-
var app = angular.module('app', ["angucomplete-alt"]);
66-
```
67-
68-
### Using local data
69-
70-
```html
71-
<angucomplete-alt id="ex1"
72-
placeholder="Search countries"
73-
pause="100"
74-
selected-object="selectedCountry"
75-
local-data="countries"
76-
search-fields="name"
77-
title-field="name"
78-
minlength="1"
79-
input-class="form-control form-control-small"/>
80-
```
81-
82-
### Using local data with custom search function
83-
84-
```html
85-
<angucomplete-alt id="ex2"
86-
placeholder="Search people"
87-
pause="300"
88-
selected-object="selectedPerson"
89-
local-data="people"
90-
local-search="localSearch"
91-
title-field="firstName,surname"
92-
description-field="twitter"
93-
image-field="pic"
94-
minlength="1"
95-
input-class="form-control form-control-small"
96-
match-class="highlight" />
97-
```
98-
99-
Local search function takes a string and returns an array of matched items.
100-
```javascript
101-
// Here is a naive implementation for matching first name, last name, or full name
102-
$scope.localSearch = function(str) {
103-
var matches = [];
104-
$scope.people.forEach(function(person) {
105-
var fullName = person.firstName + ' ' + person.surname;
106-
if ((person.firstName.toLowerCase().indexOf(str.toString().toLowerCase()) >= 0) ||
107-
(person.surname.toLowerCase().indexOf(str.toString().toLowerCase()) >= 0) ||
108-
(fullName.toLowerCase().indexOf(str.toString().toLowerCase()) >= 0)) {
109-
matches.push(person);
110-
}
111-
});
112-
return matches;
113-
};
114-
```
115-
[Example](https://ghiden.github.io/angucomplete-alt/#example2)
116-
117-
### Using remote API
118-
119-
```html
120-
<angucomplete-alt id="members"
121-
placeholder="Search members"
122-
pause="400"
123-
selected-object="testObj"
124-
remote-url="http://myserver.com/api/user/find?s="
125-
remote-url-data-field="results"
126-
title-field="firstName,surname"
127-
description-field="email"
128-
image-field="profilePic"
129-
input-class="form-control form-control-small"/>
130-
```
131-
132-
It expects the returned results from remote API to have a root object. In the above example, 'results' is an array of search results.
133-
134-
### Description of attributes
135-
| Attribute | Description | Required | Binding | Example |
136-
| :------------- |:-------------| :-----:| :-----:| :-----|
137-
| id | A unique ID for the field. [example](https://ghiden.github.io/angucomplete-alt/#example1) | Yes | @ | members |
138-
| placeholder | Placeholder text for the search field. [example](https://ghiden.github.io/angucomplete-alt/#example1) | No | @ | Search members |
139-
| maxlength | Maxlength attribute for the search field. [example](https://ghiden.github.io/angucomplete-alt/#example1) | No | attribute | 25 |
140-
| pause | The time to wait (in milliseconds) before searching when the user enters new characters. [example](https://ghiden.github.io/angucomplete-alt/#example1) | No | @ | 400 |
141-
| selected-object | Either an object in your scope or callback function. If you set an object, it will be passed to the directive with '=' sign but it is actually one-way-bound data. So, setting it from your scope has no effect on input string. If you set a callback, it gets called when selection is made. 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/#example1) | Yes | = | selectedObject or objectSelectedCallback |
142-
| selected-object-data | A second parameter which will be passed to selected-object. Only works when using selected-object. | No | = | row |
143-
| remote-url | The remote URL to hit to query for results in JSON. angucomplete will automatically append the search string on the end of this, so it must be a GET request. [example](https://ghiden.github.io/angucomplete-alt/#example5) | No | @ | http://myserver.com/api/users/find?searchstr= |
144-
| remote-url-data-field | The name of the field in the JSON object returned back that holds the Array of objects to be used for the autocomplete list. [example](https://ghiden.github.io/angucomplete-alt/#example5) | No | @ | results |
145-
| title-field | The name of the field in the JSON objects returned back that should be used for displaying the title in the autocomplete list. Note, if you want to combine fields together, you can comma separate them here (e.g. for a first and last name combined). If you want to access nested field, use dot to connect attributes (e.g. name.first). [example](https://ghiden.github.io/angucomplete-alt/#example1) | Yes | @ | firstName,lastName |
146-
| description-field | The name of the field in the JSON objects returned back that should be used for displaying the description in the autocomplete list. [example](https://ghiden.github.io/angucomplete-alt/#example6) | No | @ | twitterUsername |
147-
| image-field | The name of the field in the JSON objects returned back that should be used for displaying an image in the autocomplete list. [example](https://ghiden.github.io/angucomplete-alt/#example2) | No | @ | pic |
148-
| minlength | The minimum length of string required before searching. [example](https://ghiden.github.io/angucomplete-alt/#example1). If set to 0, it shows all items. It works both local and remote but is intended to use with local data. If used with remote API, it needs to return all items when query parameter is empty string. | No | @ | 3 |
149-
| input-name | Name for input field. This is required when you use field-required. | No | @ | |
150-
| input-class | The classes to use for styling the input box. [example](https://ghiden.github.io/angucomplete-alt/#example1) | No | @ | form-control |
151-
| match-class | If it is assigned, matching part of title is highlighted with given class style. [example](https://ghiden.github.io/angucomplete-alt/#example6) | No | @ | highlight |
152-
| local-data | The local data variable to use from your controller. Should be an array of objects. [example](https://ghiden.github.io/angucomplete-alt/#example1) | No | = | countriesList |
153-
| local-search | A function that search local data. It should take a input string and an array of items as arguments and returns an array of matched items. [example](https://ghiden.github.io/angucomplete-alt/#example2) | No | & | localSearch |
154-
| search-fields | The fields from your local data to search on (comma separate them). Each field can contain dots for accessing nested attribute. [example](https://ghiden.github.io/angucomplete-alt/#example1) | No | @ | title,description |
155-
| remote-url-request-formatter | A function that takes a query string and returns parameter(s) for GET. It should take the query string as argument and returns a key-value object. [example](https://ghiden.github.io/angucomplete-alt/#example5) | No | = | Suppose if you need to send a query keyword and a timestamp to search API, you can write a function like this in the parent scope. $scope.dataFormatFn = function(str) { return {q: str, timestamp: +new Date()}; } |
156-
| remote-url-request-with-credentials | A boolean that accepts parameters with credentials. | No | @ | true or false |
157-
| remote-url-response-formatter | A function on the scope that will modify raw response from remote API before it is rendered in the drop-down. Useful for adding data that may not be available from the API. The specified function must return the object in the format that angucomplete understands. | No | = | addImageUrlToObject |
158-
| remote-url-error-callback | A callback funciton to handle error response from $http.get | No | = | httpErrorCallbackFn |
159-
| remote-api-handler | This gives a way to fully delegate handling of remote search API. This function takes user input string and timeout promise, and it needs to return a promise. For example, if your search API is based on POST, you can use this function to create your own http handler. See example below | No | = | |
160-
| clear-selected | To clear out input field upon selecting an item, set this attribute to true. [example](https://ghiden.github.io/angucomplete-alt/#example3) | No | @ | true |
161-
| override-suggestions | To override suggestions and set the value in input field to selectedObject. [example](https://ghiden.github.io/angucomplete-alt/#example4) | No | true |
162-
| field-required | Set field to be required. Requirement for this to work is that this directive needs to be in a form and you need to provide input-name. Default class name is "autocomplete-required". [example](https://ghiden.github.io/angucomplete-alt/#example8). | No | = | a variable holding true/false |
163-
| field-required-class | Set custom class name for required. | No | @ | "match" |
164-
| text-searching | Custom string to show when search is in progress. Set this to 'false' prevents text to show up. | No | @ | "Searching for items..." |
165-
| text-no-results | Custom string to show when there is no match. Set this to 'false' prevents text to show up. | No | @ | "Not found" |
166-
| 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) |
167-
| 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 |
168-
| 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 |
169-
| focus-in | A function or expression to be called when input field gets focused. [example](https://ghiden.github.io/angucomplete-alt/#example12) | No | & | focusIn() |
170-
| focus-out | A function or expression to be called when input field lose focus. [example](https://ghiden.github.io/angucomplete-alt/#example12) | No | & | focusOut() |
171-
| disable-input | A model to control disable/enable of input field. [example page](https://ghiden.github.io/angucomplete-alt/#example13) | No | = | disableInput |
172-
| template-url | Customize the markup of the autocomplete template. [example page](https://ghiden.github.io/angucomplete-alt/#example14) | No | attribute | "/my-custom-template.html" |
173-
| focus-first | Automatically select the first match from the result list. | No | @ | true |
174-
| parse-input | A function or expression to parse input string before comparing into search process. | No | & | parseInput() |
175-
| field-tabindex | Setting the tabindex attribute on the input field. | No | @ | field-tabindex="25" |
176-
177-
178-
### Scrollbar
179-
180-
To show scrollbar, you need to set the following css style to angucomplete-dropdown class, and then the directive automatically picks it up.
181-
```css
182-
.angucomplete-dropdown {
183-
...
184-
overflow-y: auto;
185-
max-height: 200px; // your preference
186-
...
187-
}
188-
```
189-
See [example #1](https://ghiden.github.io/angucomplete-alt/#example1)
190-
191-
### Clear Input
192-
193-
To clear all angucomplete-alt input fields, send this message
194-
```js
195-
$scope.$broadcast('angucomplete-alt:clearInput');
196-
```
197-
198-
To clear an angucomplete-alt input field, send this message with id of the directive. For example, the id of the directive is 'autocomplete-1'.
199-
```js
200-
$scope.$broadcast('angucomplete-alt:clearInput', 'autocomplete-1');
201-
```
202-
203-
### Change Input
204-
205-
To set an angucomplete-alt input field, send this message with id of the directive and desired value.
206-
One can pass a simple string or an object as an argument, the same rules applied as for ```initial-value``` parameter.
207-
For example, the id of the directive is 'autocomplete-1'.
208-
```js
209-
$scope.$broadcast('angucomplete-alt:changeInput', 'autocomplete-1', 'Hello!');
210-
```
211-
212-
### Remote API Handler
213-
214-
This is an example calling search API with POST.
215-
Pass this searchAPI function to the directive as remote-api-handler.
216-
217-
```js
218-
$scope.searchAPI = function(userInputString, timeoutPromise) {
219-
return $http.post('/yourownapi/', {q: userInputString}, {timeout: timeoutPromise});
220-
}
221-
```
222-
When you use remote-api-handler, these attributes are ignored:
9+
### To install
22310
```
224-
remote-url
225-
remote-url-request-formatter
226-
remote-url-request-with-credentials
227-
```
228-
229-
### Callback behaviour
230-
231-
Callbacks ```selected-object``` and ```input-changed``` are called with the following method signature:
232-
233-
```
234-
function ($item) {
235-
236-
$item.title // or description, or image - from your angucomplete attribute configuration
237-
$item.originalObject // the actual object which was selected
238-
this.$parent // the control which caused the change, contains useful things like $index for use in ng-repeat.
239-
240-
}
241-
```
242-
243-
### Examples
244-
245-
To run examples, cd into 'examples' directory and run static http server of your choice:
246-
247-
```bash
248-
cd examples
249-
python -m SimpleHTTPServer
250-
```
251-
252-
### Contributors
253-
254-
Here is the list of [contributors](CONTRIBUTORS.md).
255-
Here is how to [contribute](CONTRIBUTING.md).
256-
Of course the easiest contribution is to give it a star!
11+
npm i --save angucomplete-alt-lucascco

0 commit comments

Comments
 (0)