Calendar undefined instance

Hi,

We catched multiple errors for code snippet below from diff users. Lib version used 3.2.0.

$(this).mobiscroll().calendar({
                theme: 'ios',
                lang: lang,
                display: 'bottom',
                dateFormat: 'dd.mm.yy',
                min: min,
                max: max,
                onBeforeShow: function(event, inst) {
                    $(".elem").blur();
                },
                onDayChange: function(event, inst) {
                    inst.setVal(event.date, true)
                },
                onBeforeClose: function (event, inst) {
                    if (!inst.**getVal()** && event.button == 'set') {
                        return false;
                    }
                },
                defaultValue: defaultValue,
            });

Logged error: StackTrace: TypeError: null is not an object (evaluating ‘inst.getVal’); Plattform: iOS; Device: iPhone10,4; OS version: 11.4.1;

P.S checked lib change log(3.2.X and 4.X) an didn’t found relevant fixes

Hi Vitalij,

I checked the above code, and created a test case, but the error did not occur for me. I tested with v3.2.0 and latest version as well. Could you describe the exact steps to reproduce the error?

Thanks,
Isti

Hi,

that was catched by 7 unique iOS users(>100 times), mostly iPnone with 11.3.1 - 11.4.1 OS versions. Exact steps to reproduce i don’t have.

My best guess will be: When calendar instance is destroyed or in process of that ($(this).mobiscroll('destroy');), onBeforeClose is triggered lastly with already destroyed instance.

Thanks for the additional info!

When and where are you calling the destroy method?

It is attached to page controller’s destroy method, which is auto triggered on page change/redraw.

P.S I do tried to trigger calendar destroy code via UI and console, when calendar is opened. Result is that calendar was firstly closed and then destroyed and no date was selected by onBeforeClose event as expected.

I can add additional checks if variables are not undefined in event function and that should be enough.

Still could not create a case to reproduce this, onBeforeClose always runs before the destroy is complete. If you can provide an example with steps to reproduce, would help a lot to identify the issue.

And you’re right, as a workaround you can check if the instance exists before calling the getVal method.

Hello,

Same issue observed in my application IPAD application
Capture
my code is like-
theme: ‘ios’,
display: ‘bubble’,
lang: this.locale.id.toLocaleUpperCase() === ‘DE-DE’ ? ‘de’ : ‘en’,
dateFormat: this.locale.DATETIME_FORMATS.imedDate.toLocaleLowerCase(),
max: this.options.maxDate,
min: this.options.minDate,
defaultValue: this.scope.i1Default,
buttons: ,
showOnFocus: false,
onSet: (event, inst) => {
this.onSet(event, inst);
},
onCancel: (event, inst) => {
this.onCancel(event, inst);
},
onClear: (event, inst) => {
this.onClear(event, inst);
},
onBeforeShow: (event, inst): boolean => {
if(inst){
return this.setBeforeShow();
}
},
onBeforeClose: (event, inst) => {
if(inst){
this.setBeforeClose();
}
},
onClose: (event, inst) => {
this.blur(event);
},
onInit: (event, inst) => {
this.instance = inst;
if (angular.isDefined(this.instance) && this.instance !== null) {
this.instance.live = false;
if (this.instance.element)
this.i1MobiscrollId = this.instance.element.id;
if (!this.instance.invokedFromRefresh) {
this.$timeout(() => {
if (this.scope.i1Model && angular.isDefined(inst) && inst !== null) {
inst.setVal(this.scope.i1Model, true, false);
}
});
}
}