Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 9ad02c6

Browse files
author
jboesch
committed
added "auto_value" option to optionally turn off setting of the current time as a value
1 parent 84f5e33 commit 9ad02c6

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

example/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ <h3 class="grey-line"><span>Initialization options</span></h3>
155155
<td>true | false</td>
156156
<td>If we blur from the input field and it's empty, populate it with our empty default value (see next line).</td>
157157
</tr>
158+
<tr>
159+
<td><a name="auto_value"></a>auto_value</td>
160+
<td>true</td>
161+
<td>true | false</td>
162+
<td>If false, it will not inject the current time as a value. Your input will be empty.</td>
163+
</tr>
158164
<tr>
159165
<td><a name="empty"></a>empty</td>
160166
<td>{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jQueryTimeAutocomplete",
33
"title": "jQueryTimeAutocomplete",
44
"description": "A time autocomplete plugin similar to how Google Calendar's time autocomplete works.",
5-
"version": "1.0.0",
5+
"version": "1.0.2",
66
"homepage": "http://7shifts.com/blog/better-time-drop-downs-for-scheduling-jquery-timeautocomplete/",
77
"repository": {
88
"type": "git",

src/jquery.timeAutocomplete.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
autoFocus: true,
3737
minLength: 0
3838
},
39+
auto_value: true,
3940
value: '',
4041
formatter: 'ampm'
4142
},
@@ -95,7 +96,11 @@
9596
if(allow_focus){
9697
self._focusAutocomplete.apply(self, arguments);
9798
}
98-
}).trigger('blur.' + namespace);
99+
});
100+
101+
if(this.options.auto_value){
102+
this.el.trigger('blur.' + namespace);
103+
}
99104

100105
},
101106

@@ -380,7 +385,11 @@
380385
this._calling_from_init = true;
381386
this.setFormatter();
382387
this._callAutocomplete();
383-
this._setValueAsTime();
388+
389+
if(this.options.auto_value){
390+
this._setValueAsTime();
391+
}
392+
384393
this._bindEvents();
385394
this._setupPlaceholder();
386395

tests/spec/timeAutocomplete.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,23 @@ describe("timeAutocomplete", function() {
4949

5050
it('should call _setupPlaceholder', function(){
5151
expect(sut._setupPlaceholder).toHaveBeenCalled();
52-
})
52+
});
53+
54+
it('should not call _setValueAsTime if this.options.auto_value is false', function(){
55+
var $ta_el = affix('input');
56+
var TimeAutocompleteInstance = new $.timeAutocomplete._raw($ta_el);
57+
spyOn(TimeAutocompleteInstance, 'setFormatter');
58+
spyOn(TimeAutocompleteInstance, '_callFormatterMethod');
59+
spyOn(TimeAutocompleteInstance, '_callAutocomplete');
60+
spyOn(TimeAutocompleteInstance, '_bindEvents');
61+
spyOn(TimeAutocompleteInstance, '_setupPlaceholder');
62+
spyOn(TimeAutocompleteInstance, '_setValueAsTime');
63+
64+
TimeAutocompleteInstance.options.auto_value = false;
65+
TimeAutocompleteInstance.render();
66+
67+
expect(TimeAutocompleteInstance._setValueAsTime).not.toHaveBeenCalled();
68+
});
5369

5470
});
5571

timeAutocomplete.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"time",
77
"autocomplete"
88
],
9-
"version": "1.0.1",
9+
"version": "1.0.2",
1010
"author": {
1111
"name": "Jordan Boesch"
1212
},

0 commit comments

Comments
 (0)