Skip to content

Add altRedirectFocus option #725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
"unused": true,
"boss": true,
"eqnull": true,
"node": true,
"es5": true
"node": true
}
3 changes: 3 additions & 0 deletions src/docs/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ <h3>Alt Field Options</h3>

<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>
Expand Down
14 changes: 9 additions & 5 deletions src/jquery-ui-timepicker-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
altTimeFormat: null,
altSeparator: null,
altTimeSuffix: null,
altRedirectFocus: true,
pickerTimeFormat: null,
pickerTimeSuffix: null,
showTimepicker: true,
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"jQuery",
"$",
"QUnit",
"jasmine",
"module",
"test",
"asyncTest",
Expand Down
35 changes: 35 additions & 0 deletions test/jquery-ui-timepicker-addon_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});