Skip to content

Commit 7b546a7

Browse files
committed
Improved j-DatePicker component.
1 parent 2054d1d commit 7b546a7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

j-DatePicker/component.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ COMPONENT('datepicker', 'today:Set today;clear:Clear;firstday:-1', function(self
279279
dt.setMinutes(+(time[1] || '0'));
280280
dt.setSeconds(+(time[2] || '0'));
281281
}
282+
} else {
283+
282284
}
283285

284286
self.opt.scope && M.scope(self.opt.scope);
@@ -360,8 +362,8 @@ COMPONENT('datepicker', 'today:Set today;clear:Clear;firstday:-1', function(self
360362
if (self.opt.clock) {
361363
var cols = self.opt.ampm ? ' col-3' : ' col-2';
362364
var timepicker = '<div class="{0}-time"><i class="ti ti-clock"></i><div class="{0}-select-wrapper{1}">{{ content }}</div></div>'.format(cls, cols);
363-
var selecthours = '<div class="{0}-selecticon"><select id="{0}-hours" class="{0}-hours">{{ options }}</select><i class="ti ti-angle-down"></i></div>'.format(cls);
364-
var selectminutes = '<div class="{0}-selecticon"><select id="{0}-minutes" class="{0}-minutes">{{ options }}</select><i class="ti ti-angle-down"></i></div>'.format(cls);
365+
var selecthours = '<div class="{0}-selecticon"><select class="{0}-hours">{{ options }}</select><i class="ti ti-angle-down"></i></div>'.format(cls);
366+
var selectminutes = '<div class="{0}-selecticon"><select class="{0}-minutes">{{ options }}</select><i class="ti ti-angle-down"></i></div>'.format(cls);
365367
var selectampm = '';
366368

367369
var hoursopt = [];
@@ -385,7 +387,7 @@ COMPONENT('datepicker', 'today:Set today;clear:Clear;firstday:-1', function(self
385387
}
386388

387389
if (self.opt.ampm)
388-
selectampm = '<div class="{0}-selecticon ampm"><select id="{0}-ampm" class="{0}-ampm"><option value="am">AM</option><option value="pm">PM</option></select><i class="ti ti-angle-down"></i></div>'.format(cls);
390+
selectampm = '<div class="{0}-selecticon ampm"><select class="{0}-ampm"><option value="am">AM</option><option value="pm">PM</option></select><i class="ti ti-angle-down"></i></div>'.format(cls);
389391

390392
selecthours = selecthours.args({ options: hoursopt.join('') });
391393
selectminutes = selectminutes.args({ options: minutesopt.join('') });
@@ -625,6 +627,23 @@ COMPONENT('datepicker', 'today:Set today;clear:Clear;firstday:-1', function(self
625627

626628
value = new Date((value || NOW).getTime());
627629

630+
if (self.opt.clock) {
631+
var hour = value.getHours();
632+
var minutes = value.getMinutes().toString().padStart(2, '0');
633+
634+
self.find(cls2 + '-minutes').val(minutes);
635+
636+
if (self.opt.ampm) {
637+
var hour12 = hour % 12 || 12;
638+
var ampm = hour >= 12 ? 'pm' : 'am';
639+
640+
self.find(cls2 + '-hours').val(hour12.toString().padStart(2, '0'));
641+
self.find(cls2 + '-ampm').val(ampm);
642+
} else {
643+
self.find(cls2 + '-hours').val(hour.toString().padStart(2, '0'));
644+
}
645+
}
646+
628647
var output = self.calculate(value.getFullYear(), value.getMonth(), value);
629648
var dom = self.find(cls2 + '-date');
630649

j-DatePicker/component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"datecreated": "2019-02-06T21:33:00.000Z",
3-
"dateupdated": "2025-05-07T11:58:01.000Z",
3+
"dateupdated": "2025-05-07T11:59:01.000Z",
44
"name": "j-DatePicker",
55
"jcomponent": "19|20",
66
"color": "white",

0 commit comments

Comments
 (0)