From e806222ef2167936042a9d706340975b0e6ecb9a Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 11 May 2014 23:26:23 +0200 Subject: [PATCH 1/4] Remove es5: true setting from /.jshintrc This setting throws an error in JSHint 2.0.0 and above, as explained by http://jslinterrors.com/es5-option-is-now-set-per-default --- .jshintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.jshintrc b/.jshintrc index 54c84f1..97b25f1 100644 --- a/.jshintrc +++ b/.jshintrc @@ -10,6 +10,5 @@ "unused": true, "boss": true, "eqnull": true, - "node": true, - "es5": true + "node": true } From a5537b4904c861351962c09063a6d549c3542f88 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 11 May 2014 23:05:25 +0200 Subject: [PATCH 2/4] Add test for altField focus redirection --- test/.jshintrc | 1 + test/jquery-ui-timepicker-addon_spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/test/.jshintrc b/test/.jshintrc index 744a6f2..391bd7f 100644 --- a/test/.jshintrc +++ b/test/.jshintrc @@ -15,6 +15,7 @@ "jQuery", "$", "QUnit", + "jasmine", "module", "test", "asyncTest", diff --git a/test/jquery-ui-timepicker-addon_spec.js b/test/jquery-ui-timepicker-addon_spec.js index 7da1ecf..4600a4f 100644 --- a/test/jquery-ui-timepicker-addon_spec.js +++ b/test/jquery-ui-timepicker-addon_spec.js @@ -661,4 +661,28 @@ describe('datetimepicker', function() { }); }); }); + + describe('altField', function() { + var $input; + var $altField; + var inputFocusSpy; + + beforeEach(function() { + $input = affix('input'); + $altField = affix('input'); + + inputFocusSpy = jasmine.createSpy(); + $input.focus(inputFocusSpy); + }); + + it('should redirect focus to main field', function() { + $input.datetimepicker({ + showOn: 'button', + altField: $altField, + }); + + $altField.trigger('focus'); + expect(inputFocusSpy).toHaveBeenCalled(); + }); + }); }); From a792358ac178fe673fbecd8c7d640328e3a795d7 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 11 May 2014 23:05:30 +0200 Subject: [PATCH 3/4] Add test for altRedirectFocus option --- test/jquery-ui-timepicker-addon_spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/jquery-ui-timepicker-addon_spec.js b/test/jquery-ui-timepicker-addon_spec.js index 4600a4f..8e0584d 100644 --- a/test/jquery-ui-timepicker-addon_spec.js +++ b/test/jquery-ui-timepicker-addon_spec.js @@ -684,5 +684,16 @@ describe('datetimepicker', function() { $altField.trigger('focus'); expect(inputFocusSpy).toHaveBeenCalled(); }); + + it('should not redirect focus to main field if altRedirectFocus is false', function() { + $input.datetimepicker({ + showOn: 'button', + altField: $altField, + altRedirectFocus: false, + }); + + $altField.trigger('focus'); + expect(inputFocusSpy).not.toHaveBeenCalled(); + }); }); }); From 66ba807e1bc3c13212f7481464a9ff1f56b73649 Mon Sep 17 00:00:00 2001 From: Emil Lundberg Date: Sun, 11 May 2014 23:13:11 +0200 Subject: [PATCH 4/4] Add altRedirectFocus option If set to true (default), the altField will redirect focus to the main field (this is how it always worked before this change). Otherwise, the altField will not redirect its focus, and the altField will behave as a normal text field that can be edited by the user. --- src/docs/options.html | 3 +++ src/jquery-ui-timepicker-addon.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/docs/options.html b/src/docs/options.html index 3cecb5a..22fc123 100644 --- a/src/docs/options.html +++ b/src/docs/options.html @@ -68,6 +68,9 @@

Alt Field Options

altTimeFormat
Default: (timeFormat option) - The time format to use with the altField.
+ +
altRedirectFocus
+
Default: true - Whether to immediately focus the main field whenever the altField receives focus. Effective at construction time only, changing it later has no effect.

Timezone Options

diff --git a/src/jquery-ui-timepicker-addon.js b/src/jquery-ui-timepicker-addon.js index a6028da..29209c9 100644 --- a/src/jquery-ui-timepicker-addon.js +++ b/src/jquery-ui-timepicker-addon.js @@ -99,6 +99,7 @@ altTimeFormat: null, altSeparator: null, altTimeSuffix: null, + altRedirectFocus: true, pickerTimeFormat: null, pickerTimeSuffix: null, showTimepicker: true, @@ -271,11 +272,14 @@ tp_inst.$input = $input; if (tp_inst._defaults.altField) { - tp_inst.$altInput = $(tp_inst._defaults.altField).css({ - cursor: 'pointer' - }).focus(function () { - $input.trigger("focus"); - }); + tp_inst.$altInput = $(tp_inst._defaults.altField); + if (tp_inst._defaults.altRedirectFocus === true) { + tp_inst.$altInput.css({ + cursor: 'pointer' + }).focus(function () { + $input.trigger("focus"); + }); + } } if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) {