@@ -28,6 +28,30 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
28
28
}
29
29
} ;
30
30
31
+ var selectPlaceholder = function ( args ) {
32
+ if ( args . form . placeholder ) {
33
+ var selectBox = args . fieldFrag . querySelector ( 'select' ) ;
34
+ var option = document . createElement ( 'option' ) ;
35
+ option . setAttribute ( 'value' , '' ) ;
36
+
37
+ // We only want the placeholder to show when we do not have a value on the model.
38
+ // We make ngModel builder replace all so we can use $$value$$.
39
+ option . setAttribute ( 'sf-field-model' , 'replaceAll' ) ;
40
+
41
+ // https://github.com/angular/angular.js/issues/12190#issuecomment-115277040
42
+ // emptyOption.attr('selected', true) does not like the ng-if comment.
43
+ if ( angular . version . major === 1 && angular . version . minor < 4 ) {
44
+ option . setAttribute ( 'ng-if' , '!$$value$$' ) ;
45
+ } else {
46
+ option . setAttribute ( 'ng-show' , '!$$value$$' ) ;
47
+ }
48
+
49
+ option . textContent = args . form . placeholder ;
50
+
51
+ selectBox . appendChild ( option ) ;
52
+ }
53
+ } ;
54
+
31
55
var defaults = [ sfField , ngModel , ngModelOptions , condition ] ;
32
56
decoratorsProvider . defineDecorator ( 'bootstrapDecorator' , {
33
57
textarea : { template : base + 'textarea.html' , builder : defaults } ,
@@ -38,7 +62,7 @@ function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
38
62
section : { template : base + 'section.html' , builder : [ sfField , simpleTransclusion , condition ] } ,
39
63
conditional : { template : base + 'section.html' , builder : [ sfField , simpleTransclusion , condition ] } ,
40
64
actions : { template : base + 'actions.html' , builder : defaults } ,
41
- select : { template : base + 'select.html' , builder : defaults } ,
65
+ select : { template : base + 'select.html' , builder : [ selectPlaceholder , sfField , ngModel , ngModelOptions , condition ] } ,
42
66
checkbox : { template : base + 'checkbox.html' , builder : defaults } ,
43
67
checkboxes : { template : base + 'checkboxes.html' , builder : [ sfField , ngModelOptions , ngModel , array , condition ] } ,
44
68
number : { template : base + 'default.html' , builder : defaults } ,
0 commit comments