Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(chips): interaction with Autocomplete
Browse files Browse the repository at this point in the history
Properly set require-match=true in demos so that the value is correct in the components.
Check for requiredMatch on the controller instead of on the scope.

fixes #3475

closes #4108
  • Loading branch information
Ty Potter authored and Robert Messerle committed Aug 18, 2015
1 parent e2a8f29 commit 86db4db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/chips/demoContactChips/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
md-contact-name="name"
md-contact-image="image"
md-contact-email="email"
md-require-match
md-require-match="true"
filter-selected="ctrl.filterSelected"
placeholder="To">
</md-contact-chips>
Expand Down
2 changes: 1 addition & 1 deletion src/components/chips/demoCustomInputs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2 class="md-title">Use an <code>input</code> element to build an ordered set
<br/>
<h2 class="md-title">Use <code>md-autocomplete</code> to build an ordered set of chips.</h2>

<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap md-require-match>
<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap md-require-match="true">
<md-autocomplete
md-selected-item="ctrl.selectedItem"
md-search-text="ctrl.searchText"
Expand Down
7 changes: 5 additions & 2 deletions src/components/chips/js/chipsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ function MdChipsCtrl ($scope, $mdConstant, $log, $element, $timeout) {
/** @type {number} */
this.selectedChip = -1;

/** @type {boolean} */
this.hasAutocomplete = false;


/**
* Hidden hint text for how to delete a chip. Used to give context to screen readers.
Expand Down Expand Up @@ -91,7 +94,7 @@ MdChipsCtrl.prototype.inputKeydown = function(event) {
var chipBuffer = this.getChipBuffer();
switch (event.keyCode) {
case this.$mdConstant.KEY_CODE.ENTER:
if (this.$scope.requireMatch || !chipBuffer) break;
if ((this.hasAutocomplete && this.requireMatch) || !chipBuffer) break;
event.preventDefault();
this.appendChip(chipBuffer);
this.resetChipBuffer();
Expand Down Expand Up @@ -381,7 +384,7 @@ MdChipsCtrl.prototype.configureUserInput = function(inputElement) {
};

MdChipsCtrl.prototype.configureAutocomplete = function(ctrl) {

this.hasAutocomplete = true;
ctrl.registerSelectedItemWatcher(angular.bind(this, function (item) {
if (item) {
this.appendChip(item);
Expand Down

1 comment on commit 86db4db

@lexyfeito
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello is there a way to add new chips to the collection if they are not in it?

Please sign in to comment.