@@ -34,6 +34,10 @@ angular.module('material.components.select', [
34
34
*
35
35
* @description Displays a select box, bound to an ng-model.
36
36
*
37
+ * When the select is required and uses a floating label, then the label will automatically contain
38
+ * an asterisk (`*`).<br/>
39
+ * This behavior can be disabled by using the `md-no-asterisk` attribute.
40
+ *
37
41
* @param {expression } ng-model The model!
38
42
* @param {boolean= } multiple Whether it's multiple.
39
43
* @param {expression= } md-on-close Expression to be evaluated when the select is closed.
@@ -42,6 +46,7 @@ angular.module('material.components.select', [
42
46
* @param {expression= } md-selected-text Expression to be evaluated that will return a string
43
47
* to be displayed as a placeholder in the select input box when it is closed.
44
48
* @param {string= } placeholder Placeholder hint text.
49
+ * @param md-no-asterisk {boolean=} When set to true, an asterisk will not be appended to the floating label.
45
50
* @param {string= } aria-label Optional label for accessibility. Only necessary if no placeholder or
46
51
* explicit label is present.
47
52
* @param {string= } md-container-class Class list to get applied to the `._md-select-menu-container`
@@ -227,6 +232,7 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
227
232
// grab a reference to the select menu value label
228
233
var valueEl = element . find ( 'md-select-value' ) ;
229
234
var isReadonly = angular . isDefined ( attr . readonly ) ;
235
+ var disableAsterisk = $mdUtil . parseAttributeBoolean ( attr . mdNoAsterisk ) ;
230
236
231
237
if ( containerCtrl ) {
232
238
var isErrorGetter = containerCtrl . isErrorGetter || function ( ) {
@@ -284,6 +290,13 @@ function SelectDirective($mdSelect, $mdUtil, $mdTheming, $mdAria, $compile, $par
284
290
285
291
attr . $observe ( 'placeholder' , ngModelCtrl . $render ) ;
286
292
293
+ if ( containerCtrl && containerCtrl . label ) {
294
+ attr . $observe ( 'required' , function ( value ) {
295
+ // Toggle the md-required class on the input containers label, because the input container is automatically
296
+ // applying the asterisk indicator on the label.
297
+ containerCtrl . label . toggleClass ( 'md-required' , value && ! disableAsterisk ) ;
298
+ } ) ;
299
+ }
287
300
288
301
mdSelectCtrl . setLabelText = function ( text ) {
289
302
mdSelectCtrl . setIsPlaceholder ( ! text ) ;
0 commit comments