This repository was archived by the owner on Sep 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +41
-7
lines changed Expand file tree Collapse file tree 4 files changed +41
-7
lines changed Original file line number Diff line number Diff line change 3
3
< md-content class ="md-padding " layout ="column ">
4
4
< h2 class ="md-title "> Use a custom chip template.</ h2 >
5
5
6
- < md-chips ng-model ="ctrl.roFruitNames " readonly ="ctrl.readonly ">
7
- < md-chip-template >
8
- < strong > {{$chip}}</ strong >
9
- < em > (fruit)</ em >
10
- </ md-chip-template >
11
- </ md-chips >
6
+ < form name ="fruitForm ">
7
+ < md-chips ng-model ="ctrl.roFruitNames " name ="fruitName " readonly ="ctrl.readonly " md-max-chips ="5 ">
8
+ < md-chip-template >
9
+ < strong > {{$chip}}</ strong >
10
+ < em > (fruit)</ em >
11
+ </ md-chip-template >
12
+ </ md-chips >
13
+
14
+ < div class ="errors " ng-messages ="fruitForm.fruitName.$error ">
15
+ < div ng-message ="md-max-chips "> The maxmium of chips is reached.</ div >
16
+ </ div >
17
+ </ form >
18
+
12
19
13
20
< br />
14
21
< h2 class ="md-title "> Use the default chip template.</ h2 >
Original file line number Diff line number Diff line change 1
1
( function ( ) {
2
2
'use strict' ;
3
3
angular
4
- . module ( 'chipsDemo' , [ 'ngMaterial' ] )
4
+ . module ( 'chipsDemo' , [ 'ngMaterial' , 'ngMessages' ] )
5
5
. controller ( 'BasicDemoCtrl' , DemoCtrl ) ;
6
6
7
7
function DemoCtrl ( $timeout , $q ) {
Original file line number Diff line number Diff line change
1
+ .errors {
2
+ font-size : 12px ;
3
+ color : rgb (221 ,44 ,0 );
4
+ margin-top : 10px ;
5
+ }
6
+
1
7
.custom-chips {
2
8
.md-chip {
3
9
position : relative ;
Original file line number Diff line number Diff line change 67
67
* displayed when there is at least one item in the list
68
68
* @param {boolean= } readonly Disables list manipulation (deleting or adding list items), hiding
69
69
* the input and delete buttons
70
+ * @param {number= } md-max-chips The maximum number of chips allowed to add through user input.
71
+ * <br/><br/>The validation property `md-max-chips` can be used when the max chips
72
+ * amount is reached.
70
73
* @param {expression } md-transform-chip An expression of form `myFunction($chip)` that when called
71
74
* expects one of the following return values:
72
75
* - an object representing the `$chip` input string
94
97
* </md-chips>
95
98
* </hljs>
96
99
*
100
+ * <h3>Validation</h3>
101
+ * When using [ngMessages](https://docs.angularjs.org/api/ngMessages), you can show errors based
102
+ * on our custom validators.
103
+ * <hljs lang="html">
104
+ * <form name="userForm">
105
+ * <md-chips
106
+ * name="fruits"
107
+ * ng-model="myItems"
108
+ * placeholder="Add an item"
109
+ * md-max-chips="5">
110
+ * </md-chips>
111
+ * <div ng-messages="userForm.fruits.$error" ng-if="userForm.$dirty">
112
+ * <div ng-message="md-max-chips">You reached the maximum amount of chips</div>
113
+ * </div>
114
+ * </form>
115
+ * </hljs>
116
+ *
97
117
*/
98
118
99
119
177
197
readonly : '=readonly' ,
178
198
placeholder : '@' ,
179
199
secondaryPlaceholder : '@' ,
200
+ maxChips : '@mdMaxChips' ,
180
201
transformChip : '&mdTransformChip' ,
181
202
onAppend : '&mdOnAppend' ,
182
203
onAdd : '&mdOnAdd' ,
You can’t perform that action at this time.
0 commit comments