Permalink
Browse files

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

…ble textfieldview
  • Loading branch information...
1 parent a12b67f commit fd214896917aa4a8271ded72a86949edfd2a42d6 Bogdan Balc committed with etgryphon Apr 4, 2011
Showing with 63 additions and 12 deletions.
  1. +37 −0 frameworks/calendar/tests/views/datepicker/ui.js
  2. +26 −12 frameworks/calendar/views/datepicker.js
@@ -8,6 +8,15 @@
var pane = SC.ControlTestPane.design()
.add("basic", SCUI.DatePickerView, {
layout: {width: 175, height: 25}
+ })
+ .add("textfield disabled", SCUI.DatePickerView, {
+ layout: {width: 175, height: 25},
+ isTextFieldEnabled: NO
+ })
+ .add("datepicker disabled, textfield disabled", SCUI.DatePickerView, {
+ layout: {width: 175, height: 25},
+ isTextFieldEnabled: NO,
+ isEnabled: NO
});
pane.show(); // add a test to show the test pane
@@ -18,3 +27,31 @@ window.pane = pane ;
//
module("Basic Tests", pane.standardSetup());
+test("textfield enabled, test if it's enabled by default", function() {
+ var view = pane.view("basic");
+ var textfield = view.getPath("childViews.0");
+ equals(textfield.get('isEnabled'), YES, 'textfield should be enabled by default');
+});
+
+test("textfield enabled, test isEnabled binding", function() {
+ var view = pane.view("basic");
+ SC.RunLoop.begin();
+ view.set('isEnabled', NO);
+ SC.RunLoop.end();
+ var textfield = view.getPath("childViews.0");
+ equals(textfield.get('isEnabled'), NO, 'textfield should be disabled when basic datepicker is disabled');
+});
+
+test("textfield disabled, test if it's really disabled", function() {
+ var textfield = pane.view("textfield disabled").getPath("childViews.0");
+ equals(textfield.get('isEnabled'), NO, 'textfield should be really disabled');
+});
+
+test("textfield disabled, check that it doesn't change when enabling the datepicker", function() {
+ var view = pane.view("datepicker disabled, textfield disabled");
+ var textfield = view.getPath("childViews.0");
+ SC.RunLoop.begin();
+ view.set('isEnabled', YES);
+ SC.RunLoop.end();
+ equals(textfield.get('isEnabled'), NO, 'textfield should be really disabled');
+});
@@ -31,6 +31,13 @@ SCUI.DatePickerView = SC.View.extend(
isEditing: NO,
+ /**
+ The isTextFieldEnabled property determines if the textfield view is enabled
+
+ @property {Boolean}
+ */
+ isTextFieldEnabled: YES,
+
// @private
_textfield: null,
_date_button: null,
@@ -57,20 +64,27 @@ SCUI.DatePickerView = SC.View.extend(
// init the dateString to whatever date we're starting with (if present)
this.set('dateString', this._genDateString(this.get('date')));
+ var textFieldDesign = {
+ layout: {left: 0, top: 0, right: 0, bottom: 0},
+ classNames: ['scui-datechooser-text'],
+ isEnabled: YES,
+ valueBinding: SC.Binding.from('.dateString', that),
+ hintBinding: SC.Binding.from('hint', that),
+ mouseDown: function (evt) {
+ that.toggle();
+ sc_super();
+ }
+ };
+
+ if (this.get('isTextFieldEnabled')) {
+ textFieldDesign.isEnabledBinding = SC.binding('isEnabled', that);
+ } else {
+ textFieldDesign.isEnabled = NO;
+ }
+
// First, Build the Textfield for the date chooser
view = this._textfield = this.createChildView(
- SC.TextFieldView.design( {
- layout: {left: 0, top: 0, right: 0, bottom: 0},
- classNames: ['scui-datechooser-text'],
- isEnabled: YES,
- isEnabledBinding: SC.binding('isEnabled', that),
- valueBinding: SC.Binding.from('.dateString', that),
- hintBinding: SC.Binding.from('hint', that),
- mouseDown: function (evt) {
- that.toggle();
- sc_super();
- }
- })
+ SC.TextFieldView.design(textFieldDesign)
);
childViews.push(view);
this.bind('isEditing', SC.Binding.from('isEditing', view).oneWay());

0 comments on commit fd21489

Please sign in to comment.