Skip to content

Commit 9866014

Browse files
authored
fix(calendar): trigger native change event on select
The native change event should be triggered whenever a date is selected from the picker and the input field blurs. Currently it is only triggered when the dates input field has been changed manually and the field blurs. I adopted the same method for this as in checkbox or dropdown
1 parent 994e053 commit 9866014

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/definitions/modules/calendar.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ $.fn.calendar = function(parameters) {
4343
'20': {'row': 3, 'column': 1 },
4444
'30': {'row': 2, 'column': 1 }
4545
},
46-
numberText = ['','one','two','three','four','five','six','seven','eight']
46+
numberText = ['','one','two','three','four','five','six','seven','eight'],
47+
selectionComplete = false
4748
;
4849

4950
$allModules
@@ -211,6 +212,20 @@ $.fn.calendar = function(parameters) {
211212
}
212213
},
213214

215+
trigger: {
216+
change: function() {
217+
var
218+
inputElement = $input[0]
219+
;
220+
if(inputElement) {
221+
var events = document.createEvent('HTMLEvents');
222+
module.verbose('Triggering native change event');
223+
events.initEvent('change', true, false);
224+
inputElement.dispatchEvent(events);
225+
}
226+
}
227+
},
228+
214229
create: {
215230
calendar: function () {
216231
var i, r, c, p, row, cell, pageGrid;
@@ -620,6 +635,10 @@ $.fn.calendar = function(parameters) {
620635
var text = formatter.datetime(date, settings);
621636
$input.val(text);
622637
}
638+
if(selectionComplete){
639+
module.trigger.change();
640+
selectionComplete = false;
641+
}
623642
}
624643
},
625644

@@ -845,15 +864,18 @@ $.fn.calendar = function(parameters) {
845864
(settings.type === 'year' && mode === 'year');
846865
if (complete) {
847866
var canceled = module.set.date(date) === false;
848-
if (!canceled && settings.closable) {
849-
module.popup('hide');
850-
//if this is a range calendar, focus the container or input. This will open the popup from its event listeners.
851-
var endModule = module.get.calendarModule(settings.endCalendar);
852-
if (endModule) {
853-
if (endModule.setting('on') !== 'focus') {
854-
endModule.popup('show');
867+
if (!canceled) {
868+
selectionComplete = true;
869+
if(settings.closable) {
870+
module.popup('hide');
871+
//if this is a range calendar, focus the container or input. This will open the popup from its event listeners.
872+
var endModule = module.get.calendarModule(settings.endCalendar);
873+
if (endModule) {
874+
if (endModule.setting('on') !== 'focus') {
875+
endModule.popup('show');
876+
}
877+
endModule.focus();
855878
}
856-
endModule.focus();
857879
}
858880
}
859881
} else {

src/definitions/modules/checkbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,10 @@ $.fn.checkbox = function(parameters) {
556556
trigger: {
557557
change: function() {
558558
var
559-
events = document.createEvent('HTMLEvents'),
560559
inputElement = $input[0]
561560
;
562561
if(inputElement) {
562+
var events = document.createEvent('HTMLEvents');
563563
module.verbose('Triggering native change event');
564564
events.initEvent('change', true, false);
565565
inputElement.dispatchEvent(events);

src/definitions/modules/dropdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,10 +1637,10 @@ $.fn.dropdown = function(parameters) {
16371637
trigger: {
16381638
change: function() {
16391639
var
1640-
events = document.createEvent('HTMLEvents'),
16411640
inputElement = $input[0]
16421641
;
16431642
if(inputElement) {
1643+
var events = document.createEvent('HTMLEvents');
16441644
module.verbose('Triggering native change event');
16451645
events.initEvent('change', true, false);
16461646
inputElement.dispatchEvent(events);

0 commit comments

Comments
 (0)