guylabs / ion-autocomplete

A configurable Ionic directive for an autocomplete dropdown
MIT License
264 stars 88 forks source link

Setting value when clicking on another element #215

Closed fakeheal closed 7 years ago

fakeheal commented 7 years ago

I have an ion-autocomplete input.

<div class="list padding">
  <label class="item item-input item-icon-right">
    <i class="icon ion-search placeholder-icon"></i>
    <input type="text" placeholder="" ion-autocomplete type="text" class="ion-autocomplete"
           autocomplete="off"
           ng-model="model"
           id="tagsAutocomplete"
           selected-items="selectedItems"
           max-selected-items="3"
           item-view-value-key="name"
           item-value-key="id"
           items-method="performSearch(query)"
           cancel-label="Ready"
           select-items-label="Tags:"
           selected-items-label="Chosen:"
           cancel-button-clicked-method="doneClicked(callback)">
  </label>
</div>

And it works as expected, but below this input I have a "tag cloud" with most popular tags and I want when an user clicks on those tags to set the tag as chosen in the input. I've read about pre-populating ion-autocomplete, but I have no idea how to do it after the autocomplete is initialized.

This is an element from my "tag cloud": <a href="#" class="tag" ng-click="setInSearch(tag)" ng-class="{selected: tag.isSelected}">{{tag.name}}</a>

PS: I believe I cannot label this issue as a question myself.

fakeheal commented 7 years ago

I set the external-model to selectedTags. In my $scope.doneClicked = function() I populate that array. As well as when clicking in the most popular tags link, mentioned above. However in this library this: scope.$watch("viewModel.externalModel", function (newModel, oldModel, scope) {} is not called unless a third argument is passed - true. I'm not expert in AngularJS, so tell me if I'm doing something wrong or this parameter should be included in the library. Thanks in advance.

guylabs commented 7 years ago

Hi

I am sorry for the late response but I could not reply earlier.

Well did you do it the following way with the model-to-item-method method? https://github.com/guylabs/ion-autocomplete#the-model-to-item-method

Regards,

Guy

guylabs commented 7 years ago

Hi

any news on this? I will close the issue now due to inactivity. If you still have some comments or other inquiries, then please comment and reopen the issue.

Thanks and regards,

Guy