Skip to content

Commit b4292b6

Browse files
Ty Potterkennethcachia
Ty Potter
authored andcommitted
fix(chips): interaction with Autocomplete
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 angular#3475 closes angular#4108
1 parent eac7fd2 commit b4292b6

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/components/chips/demoContactChips/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
md-contact-name="name"
88
md-contact-image="image"
99
md-contact-email="email"
10-
md-require-match
10+
md-require-match="true"
1111
filter-selected="ctrl.filterSelected"
1212
placeholder="To">
1313
</md-contact-chips>

src/components/chips/demoCustomInputs/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h2 class="md-title">Use an <code>input</code> element to build an ordered set
1515
<br/>
1616
<h2 class="md-title">Use <code>md-autocomplete</code> to build an ordered set of chips.</h2>
1717

18-
<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap md-require-match>
18+
<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap md-require-match="true">
1919
<md-autocomplete
2020
md-selected-item="ctrl.selectedItem"
2121
md-search-text="ctrl.searchText"

src/components/chips/js/chipsController.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ function MdChipsCtrl ($scope, $mdConstant, $log, $element, $timeout) {
4747
/** @type {number} */
4848
this.selectedChip = -1;
4949

50+
/** @type {boolean} */
51+
this.hasAutocomplete = false;
52+
5053

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

383386
MdChipsCtrl.prototype.configureAutocomplete = function(ctrl) {
384-
387+
this.hasAutocomplete = true;
385388
ctrl.registerSelectedItemWatcher(angular.bind(this, function (item) {
386389
if (item) {
387390
this.appendChip(item);

0 commit comments

Comments
 (0)