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

Commit

Permalink
feat(chips): allows user to require a matched item - used with autoco…
Browse files Browse the repository at this point in the history
…mplete
  • Loading branch information
Robert Messerle committed Apr 16, 2015
1 parent a09ba97 commit 736cbdb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/chips/demoContactChips/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
md-contact-name="name"
md-contact-image="image"
md-contact-email="email"
md-require-match
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 @@ -18,7 +18,7 @@

<p>Use <code>&lt;md-autocomplete&gt;</code> to build an ordered set of chips.</p>

<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap>
<md-chips ng-model="ctrl.selectedVegetables" md-autocomplete-snap md-require-match>
<md-autocomplete
md-selected-item="ctrl.selectedItem"
md-search-text="ctrl.searchText"
Expand Down
1 change: 1 addition & 0 deletions src/components/chips/js/chipsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
var chipBuffer;
switch (event.keyCode) {
case this.$mdConstant.KEY_CODE.ENTER:
if (this.$scope.requireMatch) break;
chipBuffer = this.getChipBuffer();
if (chipBuffer) {
event.preventDefault();
Expand Down
11 changes: 10 additions & 1 deletion src/components/chips/js/chipsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
secondaryPlaceholder: '@',
mdOnAppend: '&',
deleteHint: '@',
deleteButtonLabel: '@'
deleteButtonLabel: '@',
requireMatch: '=?mdRequireMatch'
}
};

Expand Down Expand Up @@ -218,6 +219,14 @@
* Configures controller and transcludes.
*/
return function postLink(scope, element, attrs, controllers) {

//-- give optional properties with no value a boolean true by default
angular.forEach(scope.$$isolateBindings, function (binding, key) {
if (binding.optional && angular.isUndefined(scope[key])) {
scope[key] = attr.hasOwnProperty(attr.$normalize(binding.attrName));
}
});

$mdTheming(element);
var mdChipsCtrl = controllers[0];
mdChipsCtrl.chipContentsTemplate = chipContentsTemplate;
Expand Down
12 changes: 11 additions & 1 deletion src/components/chips/js/contactChipsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
var MD_CONTACT_CHIPS_TEMPLATE = '\
<md-chips class="md-contact-chips"\
ng-model="$mdContactChipsCtrl.contacts"\
md-require-match="$mdContactChipsCtrl.requireMatch"\
md-autocomplete-snap>\
<md-autocomplete\
md-menu-class="md-contact-chips-suggestions"\
Expand Down Expand Up @@ -110,12 +111,21 @@
contactImage: '@mdContactImage',
contactEmail: '@mdContactEmail',
filterSelected: '=',
contacts: '=ngModel'
contacts: '=ngModel',
requireMatch: '=?mdRequireMatch'
}
};

function compile(element, attr) {
return function postLink(scope, element, attrs, controllers) {

//-- give optional properties with no value a boolean true by default
angular.forEach(scope.$$isolateBindings, function (binding, key) {
if (binding.optional && angular.isUndefined(scope[key])) {
scope[key] = attr.hasOwnProperty(attr.$normalize(binding.attrName));
}
});

$mdTheming(element);
element.attr('tabindex', '-1');
};
Expand Down

0 comments on commit 736cbdb

Please sign in to comment.