You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then the user is just able to select three items out of the returned items and also delete them again. The given `ng-model` is an
299
+
Then the user is just able to select three items out of the returned items and also delete them again. The given `ng-model` is an
295
300
array if multiple items are selected.
296
301
302
+
You can also set a scope variable instead of a fixed value such that you can dynamically change the `max-selected-items` property according to your
303
+
requirements.
304
+
297
305
### The `items-clicked-method`
298
306
299
-
You are able to pass a function to the `items-clicked-method` attribute to be notified when an item is clicked. The name of the
307
+
You are able to pass a function to the `items-clicked-method` attribute to be notified when an item is clicked. The name of the
300
308
parameter of the function must be `callback`. Here is an example:
301
309
302
310
Define the callback in your scope:
303
311
```javascript
304
312
$scope.clickedMethod=function (callback) {
305
313
// print out the selected item
306
-
console.log(callback.item);
307
-
314
+
console.log(callback.item);
315
+
308
316
// print out the component id
309
317
console.log(callback.componentId);
310
-
318
+
311
319
// print out the selected items if the multiple select flag is set to true and multiple elements are selected
312
-
console.log(callback.selectedItems);
320
+
console.log(callback.selectedItems);
321
+
322
+
// print out the selected items as an array
323
+
console.log(callback.selectedItemsArray);
313
324
}
314
325
```
315
326
@@ -322,7 +333,7 @@ Then you get a callback object with the clicked/selected item and the selected i
322
333
323
334
### The `items-removed-method`
324
335
325
-
You are able to pass a function to the `items-removed-method` attribute to be notified when an item is removed from a multi-select list. The name of the
336
+
You are able to pass a function to the `items-removed-method` attribute to be notified when an item is removed from a multi-select list. The name of the
326
337
parameter of the function must be `callback`. It is similar to items-clicked-method. This attribute has no defined behaviour for a single select list.
327
338
328
339
Here is an example:
@@ -331,13 +342,16 @@ Define the callback in your scope:
331
342
```javascript
332
343
$scope.removedMethod=function (callback) {
333
344
// print out the removed item
334
-
console.log(callback.item);
345
+
console.log(callback.item);
335
346
336
347
// print out the component id
337
348
console.log(callback.componentId);
338
-
349
+
339
350
// print out the selected items
340
-
console.log(callback.selectedItems);
351
+
console.log(callback.selectedItems);
352
+
353
+
// print out the selected items as an array
354
+
console.log(callback.selectedItemsArray);
341
355
}
342
356
```
343
357
@@ -350,16 +364,16 @@ Then you get a callback object with the removed item and the selected items.
350
364
351
365
### External model
352
366
353
-
The two way binded external model (`external-model` attribute on the component) is used to prepopulate the selected items with the model value. The [`model-to-item-method`](#the-model-to-item-method) is used to get the view item to the model and then the item is selected in the
354
-
component. Be aware that the `external-model` is not updated by the component when an item is selected. It is just used to prepopulate or clear the selected items. If you need to get the current selected items you are able
367
+
The two way binded external model (`external-model` attribute on the component) is used to prepopulate the selected items with the model value. The [`model-to-item-method`](#the-model-to-item-method) is used to get the view item to the model and then the item is selected in the
368
+
component. Be aware that the `external-model` is not updated by the component when an item is selected. It is just used to prepopulate or clear the selected items. If you need to get the current selected items you are able
355
369
to read the value of the `ng-model`. For an example have a look at the [`model-to-item-method`](#the-model-to-item-method) documentation.
356
370
357
371
If you need to clear the selected items then you are able to set the `external-model` to an empty array (another value is not clearing the selected items).
358
372
359
373
### The `model-to-item-method`
360
374
361
-
This method is used if you want to prepopulate the model of the `ion-autocomplete` component. The [external model](#external-model) needs
362
-
to have the same data as it would have when you select the items by hand. The component then takes the model values
375
+
This method is used if you want to prepopulate the model of the `ion-autocomplete` component. The [external model](#external-model) needs
376
+
to have the same data as it would have when you select the items by hand. The component then takes the model values
363
377
and calls the specified `model-to-item-method` to resolve the item from the back end and select it such that it is preselected.
364
378
365
379
Here a small example:
@@ -368,7 +382,7 @@ Define the `model-to-item-method` and `external-model` in your scope:
368
382
```javascript
369
383
$scope.modelToItemMethod=function (modelValue) {
370
384
371
-
// get the full model item from the model value and return it. You need to implement the `getModelItem` method by yourself
385
+
// get the full model item from the model value and return it. You need to implement the `getModelItem` method by yourself
372
386
// as this is just a sample. The method needs to retrieve the whole item (like the `items-method`) from just the model value.
373
387
var modelItem =getModelItem(modelValue);
374
388
return modelItem;
@@ -392,17 +406,20 @@ Note that the parameter for the `model-to-item-method` needs to be named `modelV
392
406
393
407
### The `cancel-button-clicked-method` (same as done button)
394
408
395
-
You are able to pass a function to the `cancel-button-clicked-method` attribute to be notified when the cancel/done button is clicked to close the modal. The name of the
409
+
You are able to pass a function to the `cancel-button-clicked-method` attribute to be notified when the cancel/done button is clicked to close the modal. The name of the
396
410
parameter of the function must be `callback`. Here is an example:
You are able to set this is on each component if you have multiple components built up in a ng-repeat where you do not want to have multiple `items-method`
426
-
for each component because you want to display other items in each component. You will also get it in the `items-clicked-method` callback object such that you just
442
+
You are able to set this is on each component if you have multiple components built up in a ng-repeat where you do not want to have multiple `items-method`
443
+
for each component because you want to display other items in each component. You will also get it in the `items-clicked-method` callback object such that you just
427
444
need to define one callback method and you can distinguish the calls with the `componentId` attribute right inside the method.
428
445
429
446
### Placeholder
@@ -462,13 +479,13 @@ You are also able to set an own template for the autocomplete component (default
This way you are able to override the default template (the `template` variable [here](https://github.com/guylabs/ion-autocomplete/blob/master/src/ion-autocomplete.js#L68))
482
+
This way you are able to override the default template (the `template` variable [here](https://github.com/guylabs/ion-autocomplete/blob/master/src/ion-autocomplete.js#L68))
466
483
and use your own template. The component will use the default template if the `template-url` is not defined.
467
484
468
485
You are able to use all the configurable attributes as expressions in your template. I would advise to use the default template as base template
469
486
and then add your custom additions to it.
470
487
471
-
> Please also take care when you change how the items are shown or what method is called if an item is clicked,
488
+
> Please also take care when you change how the items are shown or what method is called if an item is clicked,
472
489
> because changing this could make the component unusable.
473
490
474
491
You will need to set the proper `randomCssClass` for the outer most div container in your template and you can get the value by using the `{{viewModel.randomCssClass}}` expression
@@ -480,8 +497,8 @@ like in the following example:
480
497
481
498
### Template data
482
499
483
-
If you change the template with the `template-url` and want to pass in additional data then you are able to set
484
-
the `template-data` attribute on the directive. If you for example have a `templateData.testData` expression in your own
500
+
If you change the template with the `template-url` and want to pass in additional data then you are able to set
501
+
the `template-data` attribute on the directive. If you for example have a `templateData.testData` expression in your own
485
502
template like this:
486
503
```html
487
504
...
@@ -503,13 +520,13 @@ Then the expression in your template gets resolved properly.
503
520
504
521
### Loading icon
505
522
506
-
If you want to display a loading icon when the `items-method` promise gets resolved then you need to set the `loading-icon`
507
-
attribute to a value given by the Ionic spinner: http://ionicframework.com/docs/api/directive/ionSpinner. Then the spinner should
508
-
be shown at the right side of the search input field.
523
+
If you want to display a loading icon when the `items-method` promise gets resolved then you need to set the `loading-icon`
524
+
attribute to a value given by the Ionic spinner: http://ionicframework.com/docs/api/directive/ionSpinner. Then the spinner should
525
+
be shown at the right side of the search input field.
509
526
510
527
### Manage externally
511
528
512
-
To manage the `ion-autocomplete` component externally means that you need to handle when the search modal is shown. To enable this functionality
529
+
To manage the `ion-autocomplete` component externally means that you need to handle when the search modal is shown. To enable this functionality
513
530
you need to set the `manage-externally` attribute to `true` and then you can call the `showModal()` method on the controller. Here an example:
514
531
515
532
```javascript
@@ -525,16 +542,24 @@ this.clickButton = function () {
525
542
}
526
543
```
527
544
528
-
Then you will need to click on the button to open the search modal. This functionality is useful if the user wants to edit the selected item inside the
545
+
Then you will need to click on the button to open the search modal. This functionality is useful if the user wants to edit the selected item inside the
529
546
input field after she/he selected the item/s.
530
547
531
548
### Selected items
532
549
533
-
If you want to clear the selected items programmatically, then you are able to set the `selected-items` attribute with a two way binded model value which then gets updated
550
+
If you want to clear the selected items programmatically, then you are able to set the `selected-items` attribute with a two way binded model value which then gets updated
534
551
when the items get selected. If you want to clear them just set the given model value to an empty array.
535
552
536
553
Please *do not* use it for pre populating the selected items. For this use the standard `ng-model` value and [the `model-to-item-method`](#the-model-to-item-method).
537
554
555
+
### Clear on select
556
+
557
+
This option is to clear the search input when an item is selected. You need to set it to `true` as in the following example to enable this functionality:
All value keys are parsed with the Angular `$parse` service such that you are able to use expressions like in the following
@@ -564,9 +589,9 @@ name attribute of the child object:
564
589
## Debouncing
565
590
566
591
If you want to debounce the search input field request, then you are able to set the `ng-model-options` attribute on the input field where you define the `ion-autocomplete`
567
-
directive. These options will then be added to the search input field. Be aware that when you add a debounce the update of the model value will also be debounced the
592
+
directive. These options will then be added to the search input field. Be aware that when you add a debounce the update of the model value will also be debounced the
568
593
same amount as the request to the `items-method`. Here a small example:
0 commit comments