Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added isTextFieldEnabled property on date picker to allow enable/disa…

…ble textfieldview
  • Loading branch information...
commit fd214896917aa4a8271ded72a86949edfd2a42d6 1 parent a12b67f
authored etgryphon committed
37  frameworks/calendar/tests/views/datepicker/ui.js
@@ -8,6 +8,15 @@
8 8
 var pane = SC.ControlTestPane.design()
9 9
   .add("basic", SCUI.DatePickerView, {
10 10
     layout: {width: 175, height: 25}
  11
+  })
  12
+  .add("textfield disabled", SCUI.DatePickerView, {
  13
+    layout: {width: 175, height: 25},
  14
+    isTextFieldEnabled: NO
  15
+  })
  16
+  .add("datepicker disabled, textfield disabled", SCUI.DatePickerView, {
  17
+    layout: {width: 175, height: 25},
  18
+    isTextFieldEnabled: NO,
  19
+    isEnabled: NO
11 20
   });
12 21
   
13 22
 pane.show(); // add a test to show the test pane
@@ -18,3 +27,31 @@ window.pane = pane ;
18 27
 // 
19 28
 module("Basic Tests", pane.standardSetup());
20 29
 
  30
+test("textfield enabled, test if it's enabled by default", function() {
  31
+  var view = pane.view("basic");
  32
+  var textfield = view.getPath("childViews.0");
  33
+  equals(textfield.get('isEnabled'), YES, 'textfield should be enabled by default');
  34
+});
  35
+
  36
+test("textfield enabled, test isEnabled binding", function() {
  37
+  var view = pane.view("basic");
  38
+  SC.RunLoop.begin();
  39
+  view.set('isEnabled', NO);
  40
+  SC.RunLoop.end();
  41
+  var textfield = view.getPath("childViews.0");
  42
+  equals(textfield.get('isEnabled'), NO, 'textfield should be disabled when basic datepicker is disabled');
  43
+});
  44
+
  45
+test("textfield disabled, test if it's really disabled", function() {
  46
+  var textfield = pane.view("textfield disabled").getPath("childViews.0");
  47
+  equals(textfield.get('isEnabled'), NO, 'textfield should be really disabled');
  48
+});
  49
+
  50
+test("textfield disabled, check that it doesn't change when enabling the datepicker", function() {
  51
+  var view = pane.view("datepicker disabled, textfield disabled");
  52
+  var textfield = view.getPath("childViews.0");
  53
+  SC.RunLoop.begin();
  54
+  view.set('isEnabled', YES);
  55
+  SC.RunLoop.end();
  56
+  equals(textfield.get('isEnabled'), NO, 'textfield should be really disabled');
  57
+});
38  frameworks/calendar/views/datepicker.js
@@ -31,6 +31,13 @@ SCUI.DatePickerView = SC.View.extend(
31 31
   
32 32
   isEditing: NO,
33 33
   
  34
+  /** 
  35
+    The isTextFieldEnabled property determines if the textfield view is enabled
  36
+    
  37
+    @property {Boolean}
  38
+  */
  39
+  isTextFieldEnabled: YES,
  40
+  
34 41
   // @private
35 42
   _textfield: null,
36 43
   _date_button: null,
@@ -57,20 +64,27 @@ SCUI.DatePickerView = SC.View.extend(
57 64
     // init the dateString to whatever date we're starting with (if present)
58 65
     this.set('dateString', this._genDateString(this.get('date')));
59 66
     
  67
+    var textFieldDesign = {
  68
+      layout: {left: 0, top: 0, right: 0, bottom: 0},
  69
+      classNames: ['scui-datechooser-text'],
  70
+      isEnabled: YES,
  71
+      valueBinding: SC.Binding.from('.dateString', that),
  72
+      hintBinding: SC.Binding.from('hint', that),
  73
+      mouseDown: function (evt) {
  74
+        that.toggle();
  75
+        sc_super();
  76
+      }
  77
+    };
  78
+    
  79
+    if (this.get('isTextFieldEnabled')) {
  80
+      textFieldDesign.isEnabledBinding = SC.binding('isEnabled', that);
  81
+    } else {
  82
+      textFieldDesign.isEnabled = NO;
  83
+    }
  84
+    
60 85
     // First, Build the Textfield for the date chooser
61 86
     view = this._textfield = this.createChildView( 
62  
-      SC.TextFieldView.design( {
63  
-        layout: {left: 0, top: 0, right: 0, bottom: 0},
64  
-        classNames: ['scui-datechooser-text'],
65  
-        isEnabled: YES,
66  
-        isEnabledBinding: SC.binding('isEnabled', that),
67  
-        valueBinding: SC.Binding.from('.dateString', that),
68  
-        hintBinding: SC.Binding.from('hint', that),
69  
-        mouseDown: function (evt) {
70  
-          that.toggle();
71  
-          sc_super();
72  
-        }
73  
-      })
  87
+      SC.TextFieldView.design(textFieldDesign)
74 88
     );
75 89
     childViews.push(view);
76 90
     this.bind('isEditing', SC.Binding.from('isEditing', view).oneWay());

0 notes on commit fd21489

Please sign in to comment.
Something went wrong with that request. Please try again.