Skip to content

Commit 334bde3

Browse files
committed
Add: The getDate and setDate method is available on PickerHandler
Object. close #118
1 parent 8676d23 commit 334bde3

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ https://github.com/mugifly/jquery-simple-datetimepicker/
44
1.12.0 2014-xx-xx (JST)
55
- [Add] Automatically relocate a position of a picker when picker is float-mode.
66
- [Add] Automatically destroy a picker, when an input-field has lose.
7+
- [Add] The getDate and setDate method is available on PickerHandler Object.
78
- [Change] Changed a parent element to root, when picker is float-mode (Reported by: Kupid).
89

910
1.11.0 2014-04-25 (JST)

jquery.simple-dtpicker.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ <h5><a name="event-handler_methods">Available methods in <u>handler</u> object</
351351
<li>"destroy()" - Destroy a picker.</li>
352352
<li>"getInput()" - Get a input-field object (jQuery element).</li>
353353
<li>"getPicker()" - Get a picker object (jQuery element).</li>
354+
<li>"getDate()" - Get a selected date from a picker.</li>
355+
<li>"setDate(date)" - Set a specific date to a picker.</li>
354356
<li>"hide()" - Hide a picker.</li>
355357
<li>"show()" - Show a picker.</li>
356358
<li>"isShow()" - Get the display state of a picker.</li>
@@ -440,6 +442,8 @@ <h5><a name="manual-handling_method-names">Available method-names as parameter o
440442
<li>"destroy - Destroy a picker.</li>
441443
<li>"hide" - Hide a picker.</li>
442444
<li>"show" - Show a picker.</li>
445+
<li>"getDate" - Get a selected date from a picker.</li>
446+
<li>"setDate" - Set a specific date to a picker.</li>
443447
</ul>
444448
</div>
445449

@@ -449,6 +453,8 @@ <h5>e.g. Generate a picker as inline and handle by manual.</h5>
449453
<input type="button" id="btn_manual_generate" value="Generate">
450454
<input type="button" id="btn_manual_show" value="Show">
451455
<input type="button" id="btn_manual_hide" value="Hide">
456+
<input type="button" id="btn_manual_get_date" value="getDate">
457+
<input type="button" id="btn_manual_set_date" value="setDate">
452458
<input type="button" id="btn_manual_destroy" value="Destroy">
453459
<script type="text/javascript">
454460
$(function(){
@@ -463,6 +469,13 @@ <h5>e.g. Generate a picker as inline and handle by manual.</h5>
463469
$('#btn_manual_hide').click(function(){
464470
$('#date_manual').handleDtpicker('hide');
465471
});
472+
$('#btn_manual_get_date').click(function(){
473+
var date = $('#date_manual').handleDtpicker('getDate');
474+
window.alert(date.toString());
475+
});
476+
$('#btn_manual_set_date').click(function(){
477+
$('#date_manual').handleDtpicker('setDate', new Date(2014, 04, 25, 0, 0, 0));
478+
});
466479
$('#btn_manual_destroy').click(function(){
467480
$('#date_manual').handleDtpicker('destroy');
468481
});
@@ -487,6 +500,13 @@ <h5>e.g. Generate a picker as inline and handle by manual.</h5>
487500
$(&#039;#btn_manual_hide&#039;).click(function(){
488501
$(&#039;#date_manual&#039;).handleDtpicker(&#039;hide&#039;);
489502
});
503+
$(&#039;#btn_manual_get_date&#039;).click(function(){
504+
var date = $(&#039;#date_manual&#039;).handleDtpicker(&#039;getDate&#039;);
505+
window.alert(date.toString());
506+
});
507+
$(&#039;#btn_manual_set_date&#039;).click(function(){
508+
$(&#039;#date_manual&#039;).handleDtpicker(&#039;setDate&#039;, new Date(2014, 04, 25, 0, 0, 0));
509+
});
490510
$(&#039;#btn_manual_destroy&#039;).click(function(){
491511
$(&#039;#date_manual&#039;).handleDtpicker(&#039;destroy&#039;);
492512
});

jquery.simple-dtpicker.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,27 @@
166166
$picker.hide();
167167
};
168168

169+
/* Get a selected date from a picker */
170+
PickerHandler.prototype.getDate = function(){
171+
var $picker = this.$pickerObject;
172+
var $input = this.$inputObject;
173+
return getPickedDate($picker);
174+
};
175+
176+
/* Set a specific date to a picker */
177+
PickerHandler.prototype.setDate = function(date){
178+
var $picker = this.$pickerObject;
179+
var $input = this.$inputObject;
180+
if (!isObj('Date', date)) {
181+
date = new Date(date);
182+
}
183+
184+
draw_date($picker, {
185+
"isAnim": true,
186+
"isOutputToInputObject": true
187+
}, date);
188+
};
189+
169190
/* Destroy a picker */
170191
PickerHandler.prototype.destroy = function(){
171192
var $picker = this.$pickerObject;
@@ -1247,7 +1268,7 @@
12471268
// Destroy a picker
12481269
handler.destroy();
12491270
});
1250-
1271+
12511272
// Call a event-handler
12521273
var func = $picker.data('onInit');
12531274
if (func != null) {
@@ -1279,6 +1300,24 @@
12791300
handler.hide();
12801301
}
12811302
},
1303+
setDate : function( date ) {
1304+
var $input = $(this);
1305+
var $picker = $(PickerObjects[$input.data('pickerId')]);
1306+
if ($picker != null) {
1307+
var handler = new PickerHandler($picker, $input);
1308+
// Set a date
1309+
handler.setDate(date);
1310+
}
1311+
},
1312+
getDate : function( ) {
1313+
var $input = $(this);
1314+
var $picker = $(PickerObjects[$input.data('pickerId')]);
1315+
if ($picker != null) {
1316+
var handler = new PickerHandler($picker, $input);
1317+
// Get a date
1318+
return handler.getDate();
1319+
}
1320+
},
12821321
destroy : function( ) {
12831322
var $input = $(this);
12841323
var $picker = $(PickerObjects[$input.data('pickerId')]);

t/test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,33 @@ $(function() {
6969
start(); // Done.
7070
}, 100);
7171
});
72+
73+
/* handleDtpicker method
74+
Picker is inline mode, and append into an input-field. */
75+
test('handleDtpicker method', function(){
76+
var $date_input = $('#date_input');
77+
$date_input.val('2014-10-31 00:00'); // Initial date
78+
$date_input.appendDtpicker({
79+
'inline': true
80+
});
81+
var $picker = $('.datepicker');
82+
83+
$date_input.handleDtpicker('show');
84+
equal($picker.css('display'), "block");
85+
86+
$date_input.handleDtpicker('hide');
87+
equal($picker.css('display'), "none");
88+
89+
$date_input.handleDtpicker('setDate', new Date(2014, 11, 01, 12, 10, 0));
90+
91+
// Check a date
92+
var date = $date_input.handleDtpicker('getDate');
93+
equal(date.getFullYear(), 2014);
94+
equal(date.getMonth(), 11);
95+
equal(date.getDate(), 1);
96+
equal(date.getHours(), 12);
97+
equal(date.getMinutes(), 10);
98+
});
7299

73100
/* Automatically destroy
74101
Picker is float mode, and append into an input-field. */

0 commit comments

Comments
 (0)