summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Richardson <trentrichardson@users.noreply.github.com>2014-05-12 08:18:53 -0400
committerTrent Richardson <trentrichardson@users.noreply.github.com>2014-05-12 08:18:53 -0400
commite865e72b921cb17209c2bd6de4255000847840ba (patch)
tree10e0b1e67a2da50c81d5b57672a8f5faf4983d0b
parent08b50b31867141bf4875a9cb282039f232ceb13d (diff)
parent66ba807e1bc3c13212f7481464a9ff1f56b73649 (diff)
downloadjQuery-Timepicker-Addon-e865e72b921cb17209c2bd6de4255000847840ba.zip
jQuery-Timepicker-Addon-e865e72b921cb17209c2bd6de4255000847840ba.tar.gz
jQuery-Timepicker-Addon-e865e72b921cb17209c2bd6de4255000847840ba.tar.bz2
Merge pull request #725 from emlun/redirect-focus-option
Add altRedirectFocus option
-rw-r--r--.jshintrc3
-rw-r--r--src/docs/options.html3
-rw-r--r--src/jquery-ui-timepicker-addon.js14
-rw-r--r--test/.jshintrc1
-rw-r--r--test/jquery-ui-timepicker-addon_spec.js35
5 files changed, 49 insertions, 7 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
}
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 @@
<dt>altTimeFormat</dt>
<dd><em>Default: (timeFormat option)</em> - The time format to use with the altField.</dd>
+
+ <dt>altRedirectFocus</dt>
+ <dd><em>Default: true</em> - Whether to immediately focus the main field whenever the altField receives focus. Effective at construction time only, changing it later has no effect.</dd>
</dl>
<h3>Timezone Options</h3>
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) {
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..8e0584d 100644
--- a/test/jquery-ui-timepicker-addon_spec.js
+++ b/test/jquery-ui-timepicker-addon_spec.js
@@ -661,4 +661,39 @@ 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();
+ });
+
+ 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();
+ });
+ });
});