gportela85/DateTimeField

Empty value in record leads to error in update method of picker

Closed this issue · 5 comments

This is similar to #22.
ExtJS version 6.2.1, DateTimeField commit 7077467.

We have a form with a DateTimeField bound to a date field of a model which is initially undefined.
When you click the picker the following error is thrown in the console:

ext-all-sandbox-debug.js:190363 Uncaught TypeError: Cannot read property 'getMonth' of null
at constructor.update (ext-all-sandbox-debug.js:190363)
at constructor.setHtml (ext-all-sandbox-debug.js:69906)
at constructor.onBindNotify (ext-all-sandbox-debug.js:53535)
at constructor.notify (ext-all-sandbox-debug.js:99573)
at constructor.react (ext-all-sandbox-debug.js:99768)
at constructor.notify (ext-all-sandbox-debug.js:97199)
at constructor.onTick (ext-all-sandbox-debug.js:97230)
at ext-all-sandbox-debug.js:6896
at ext-all-sandbox-debug.js:7093

Line 190363 is in the update method of Ext.picker.Date:
if (!forceRefresh && active && me.el && active.getMonth() === date.getMonth() && active.getFullYear() === date.getFullYear()) {.

To me this looks like a bug in ExtJS 6.2.1 because active isn't checked using Ext.isDate but maybe I'm wrong or you could work around it.

We really need a fix for this, is there anything I can do to get to the bottom of the cause?

Can you provide a fiddle demonstrating the issue?

The error message is different but the same that happens in our add form.
https://fiddle.sencha.com/#view/editor&fiddle/1rj3

Published a fix for it here: d4a00fa

Override below:

Ext.define(null, {
    override: 'Ext.ux.DateTimeField',
    createPicker: function() {
        var me = this,
            parentPicker = this.callSuper(),
            parentConfig = Ext.clone(parentPicker.initialConfig),
            initialConfig = Ext.clone(me.initialConfig),
            excludes = ['renderTo', 'width', 'height', 'bind'];

        // Avoiding duplicate ids error
        parentPicker.destroy();

        for (var i=0; i < excludes.length; i++) {
            if (initialConfig.hasOwnProperty([excludes[i]])) {
                delete initialConfig[excludes[i]];
            }
        }
    
        return Ext.create('Ext.ux.DateTimePicker', Ext.merge(initialConfig, parentConfig));
    }
});

Thanks Guilherme! I can confirm that it works now.