Permalink
Browse files

only updateFromWidgetInputs if showInputs is true

fixes #76
  • Loading branch information...
1 parent 41cc352 commit bbce32df002f74161cdf1367f8ff4853c309a222 @jdewit committed Feb 16, 2013
View
@@ -344,7 +344,9 @@
return;
}
- this.updateFromWidgetInputs();
+ if (this.showInputs) {
+ this.updateFromWidgetInputs();
+ }
this.$element.trigger({
'type': 'hide.timepicker',
@@ -751,10 +753,10 @@
if (this.$widget === false) {
return;
}
- var time = $('input.bootstrap-timepicker-hour', this.$widget).val() + ':' +
- $('input.bootstrap-timepicker-minute', this.$widget).val() +
- (this.showSeconds ? ':' + $('input.bootstrap-timepicker-second', this.$widget).val() : '') +
- (this.showMeridian ? ' ' + $('input.bootstrap-timepicker-meridian', this.$widget).val() : '');
+ var time = $('.bootstrap-timepicker-hour', this.$widget).val() + ':' +
+ $('.bootstrap-timepicker-minute', this.$widget).val() +
+ (this.showSeconds ? ':' + $('.bootstrap-timepicker-second', this.$widget).val() : '') +
+ (this.showMeridian ? ' ' + $('.bootstrap-timepicker-meridian', this.$widget).val() : '');
this.setTime(time);
},

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -4,12 +4,15 @@ describe('Mouse events feature', function() {
var $input1,
$input2,
$input3,
+ $input4,
$timepicker1,
$timepicker2,
$timepicker3,
+ $timepicker4,
tp1,
tp2,
- tp3;
+ tp3,
+ tp4;
beforeEach(function () {
loadFixtures('timepicker.html');
@@ -35,15 +38,27 @@ describe('Mouse events feature', function() {
showSeconds: true
});
tp3 = $timepicker3.data('timepicker');
+
+ $input4 = $('#timepicker4');
+ $timepicker4 = $input4.timepicker({
+ minuteStep: 5,
+ showInputs: false,
+ showMeridian: true,
+ template: 'modal',
+ disableFocus: true
+ });
+ tp4 = $timepicker4.data('timepicker');
});
afterEach(function () {
$input1.data('timepicker').remove();
$input2.data('timepicker').remove();
$input3.data('timepicker').remove();
+ $input4.data('timepicker').remove();
$input1.remove();
$input2.remove();
$input3.remove();
+ $input4.remove();
});
it('should be shown and trigger show events on input click', function() {
@@ -111,22 +126,54 @@ describe('Mouse events feature', function() {
it('should increment minute on button click', function() {
tp1.setTime('11:30 AM');
tp1.update();
+ tp4.setTime('11:30 AM');
+ tp4.update();
tp1.$widget.find('a[data-action="incrementMinute"]').trigger('click');
-
expect(tp1.getTime()).toBe('11:45 AM');
tp2.$widget.find('a[data-action="incrementMinute"]').trigger('click');
expect(tp2.getTime()).toBe('00:30:00 AM');
+
+ $input4.trigger('click');
+ tp4.$widget.find('a[data-action="incrementMinute"]').trigger('click');
+ tp4.$widget.find('a[data-action="decrementHour"]').trigger('click');
+ $input4.closest('modal').find('.btn-primary').trigger('click');
+ expect(tp4.getTime()).toBe('10:35 AM');
+ expect($input4.val()).toBe('10:35 AM');
});
it('should decrement minute on button click', function() {
tp1.setTime('12:30 PM');
tp1.update();
+ tp4.setTime('11:30 AM');
+ tp4.update();
tp1.$widget.find('a[data-action="decrementMinute"]').trigger('click');
-
expect(tp1.getTime()).toBe('12:15 PM');
+
+ tp4.$widget.find('a[data-action="decrementMinute"]').trigger('click');
+ expect(tp4.getTime()).toBe('11:25 AM');
+ });
+
+ it('should be 11:30:00 PM if minute is decremented on empty input', function() {
+ tp2.$widget.find('a[data-action="decrementMinute"]').trigger('click');
+ expect(tp2.getTime()).toBe('11:30:00 PM');
+ });
+
+ it('should increment second on button click', function() {
+ tp2.setTime('11:30:15 AM');
+ tp2.update();
+
+ tp2.$widget.find('a[data-action="incrementSecond"]').trigger('click');
+
+ expect(tp2.getTime()).toBe('11:30:30 AM');
+ });
+
+ it('should decrement second on button click', function() {
+ tp2.setTime('12:30:15 PM');
+ tp2.update();
+
});
it('should be 11:30:00 PM if minute is decremented on empty input', function() {
View
@@ -80,18 +80,18 @@ describe('Timepicker feature', function() {
});
it('should be configurable with data attributes', function() {
- $('body').append('<div id="hi" class="bootstrap-timepicker"><input id="timepicker4" data-template="modal" data-minute-step="30" data-modal-backdrop="true" data-show-meridian="true" type="text"/></div');
+ $('body').append('<div id="hi" class="bootstrap-timepicker"><input id="customTimepicker" data-template="modal" data-minute-step="30" data-modal-backdrop="true" data-show-meridian="true" type="text"/></div');
- var $input4 = $('body').find('#timepicker4'),
- tp4 = $input4.timepicker().data('timepicker');
+ var $customInput = $('body').find('#customTimepicker'),
+ tpCustom = $customInput.timepicker().data('timepicker');
- expect($('body').find('#timepicker4').length).toBe(1);
- expect(tp4.template).toBe('modal');
- expect(tp4.minuteStep).toBe(30, 'data-minute-step not working');
- expect(tp4.modalBackdrop).toBe(true, 'data-modal-backdrop not working');
- expect(tp4.showMeridian).toBe(true, 'data-show-meridian not working');
+ expect($('body').find('#customTimepicker').length).toBe(1);
+ expect(tpCustom.template).toBe('modal');
+ expect(tpCustom.minuteStep).toBe(30, 'data-minute-step not working');
+ expect(tpCustom.modalBackdrop).toBe(true, 'data-modal-backdrop not working');
+ expect(tpCustom.showMeridian).toBe(true, 'data-show-meridian not working');
- tp4.remove();
+ tpCustom.remove();
});
it('should have current time by default', function() {
@@ -108,14 +108,14 @@ describe('Timepicker feature', function() {
});
it('should not override time with current time if value is already set', function() {
- $('body').append('<div id="timepicker4"><input id="timepicker4Input" type="text" value="12:15 AM" /></div>');
- var $input4 = $('#timepicker4Input').timepicker(),
- tp4 = $input4.data('timepicker');
+ $('body').append('<div id="timepickerCustom"><input id="timepickerCustomInput" type="text" value="12:15 AM" /></div>');
+ var $customInput = $('#timepickerCustomInput').timepicker(),
+ tpCustom = $customInput.data('timepicker');
- expect($input4.val()).toBe('12:15 AM');
+ expect($customInput.val()).toBe('12:15 AM');
- tp4.remove();
- $('#timepicker4').remove();
+ tpCustom.remove();
+ $('#timepickerCustom').remove();
});
it('should have no value if defaultTime is set to false', function() {
@@ -9,3 +9,6 @@
<div class="bootstrap-timepicker">
<input id="timepicker3" type="text" />
</div>
+<div class="bootstrap-timepicker">
+ <input id="timepicker4" type="text" />
+</div>

0 comments on commit bbce32d

Please sign in to comment.