public
Fork of sproutit/sproutcore
Description: JavaScript Application Framework - JS library only
Homepage: http://www.sproutcore.com
Clone URL: git://github.com/mguymon/sproutcore.git
Add emptyName, emptyValue, and emptyDisabled to select_field
M Nikolas Guymon (author)
Mon Dec 01 21:11:33 -0800 2008
commit  9e6ca6e60eb7fcd8ccd00422f2bcb1b189cc54a9
tree    f0094eb76fd6412a50a0a1ba853cfa79d709f86a
parent  dc1026f62a3f3a57f19fc7501eece67f18444450
...
234
235
236
 
 
 
237
238
239
...
234
235
236
237
238
239
240
241
242
0
@@ -234,6 +234,9 @@ view_helper :select_field_view do
0
   property :sort_key
0
   property :value_key
0
   property :empty, :key => 'emptyName'
0
+  property :empty_name
0
+  property :empty_disabled
0
+  property :empty_value
0
   property :enabled, :key => 'isEnabled'
0
   bind     :objects
0
   view     'SC.SelectFieldView'
...
49
50
51
52
 
 
53
54
55
56
 
 
 
 
 
 
 
 
57
58
59
...
170
171
172
173
174
175
176
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
179
180
...
49
50
51
 
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
...
179
180
181
 
 
 
 
 
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
0
@@ -49,11 +49,20 @@ SC.SelectFieldView = SC.FieldView.extend(
0
   valueKey: null,
0
 
0
   /**
0
-    set this to non-null to place an empty option at the top of the menu.   
0
+    set this to non-null to place an empty option with this name at the top of
0
+    the menu.
0
   */
0
   emptyName: null,
0
 
0
   /**
0
+    set this to non-null to place an empty option with this value at the top
0
+    of the menu
0
+  */
0
+  emptyValue: null,
0
+
0
+  emptyDisabled: false,
0
+
0
+  /**
0
     if true, the empty name will be localized.
0
   */
0
   localize: false,
0
@@ -170,11 +179,27 @@ SC.SelectFieldView = SC.FieldView.extend(
0
      objects = this.sortObjects(objects) ; // sort'em.
0
      var html = [] ;       
0
 
0
-     var emptyName = this.get('emptyName') ;
0
-     if (emptyName) {
0
-       if (shouldLocalize) emptyName = emptyName.loc() ;
0
-       html.push('<option value="***">%@</option>'.fmt(emptyName)) ;
0
-       html.push('<option disabled="disabled"></option>') ;
0
+     var emptyName = this.get('emptyName');
0
+     var emptyValue = this.get('emptyValue');
0
+     var emptyDisabled = this.get('emptyDisabled');
0
+     
0
+     if (emptyName != null || emptyValue != null) {
0
+         if (emptyName != null ) {
0
+            if (shouldLocalize) emptyName = emptyName.loc() ;
0
+         } else {
0
+             emptyName = '';
0
+         }
0
+
0
+         if (emptyValue == null) {
0
+            emptyValue = '';
0
+         }
0
+
0
+         if (emptyDisabled) {
0
+            emptyDisabled = 'disabled="disabled" ' ;
0
+         } else {
0
+             emptyDisabled = ' ';
0
+         }
0
+       html.push('<option %@value="%@">%@</option>'.fmt(emptyDisabled,emptyName,emptyValue)) ;
0
      }
0
 
0
      // generate option elements.

Comments