Results 1 to 4 of 4

Thread: Automatically fill datefield with '01-01-1970' in grid with RowEditing

  1. #1
    Sencha User
    Join Date
    Apr 2015
    Posts
    6
    Answers
    1

    Default Answered: Automatically fill datefield with '01-01-1970' in grid with RowEditing

    I'm editing a grid that has a datefield required depending on a certain condition of another column.
    The problem I have is that when I add a row without the date value, the date '01-01-1970' apears as if I selected it. Why is this happening and what can I do to display a blank field?

    I attached an edited part of the code:
    Code:
    {
                    xtype: 'grid',
                    flex: 1,
                    height: 350,
                    width: '100%',
                    margin: '10 0 10 0',
                    plugins: [{
                        ptype: 'rowediting',
                        pluginId: 'rowEditingPlugin',
                        clicksToEdit: 2,
                        clicksToMoveEditor: 2,
                        autoCancel: true,
                        errorSummary: false,
                        listeners: { canceledit: 'onCancelClick' }
                    }],
                    bind: {
                        store: '{modelStore}'
                    },
                    tbar: [{
                        text: 'Add',
                        handler: 'onAddClick'
                    }],
                    listeners: {
                        'validateedit': function (editor, e, eOpt) {
                            var values = editor.getEditor().getValues();
                            if (values.IsRequired == "on" && values.ValidUntil == "") {
                                editor.editor.getForm().findField('ValidUntil').markInvalid('Select an expiration date!');
                                return false;
                            }
                        }
                    },
                    columns: [
                         {
                            xtype: 'datecolumn',
                            text: 'Expiration Date',
                            dataIndex: 'ValidUntil',
                            format: 'd/M/Y',
                            flex: 1,
                            editor: {
                                xtype: 'datefield',
                                allowBlank: true,
                                format: 'd/M/Y',
                                submitFormat: 'd/M/Y',
                                minValue: Ext.Date.format(new Date(), 'd/M/Y')
                            }
                        }
                        , {
                            xtype: 'booleancolumn',
                            text: 'IsRequired',
                            dataIndex: 'IsRequired',
                            trueText: 'Yes',
                            falseText: 'No',
                            flex: 1,
                            editor: {
                                xtype: 'checkbox'
                            }
                        }, {
                            xtype: 'widgetcolumn',
                            width: 90,
                            widget: {
                                xtype: 'button',
                                text: 'remove',
                                handler: 'onRemoveClick'
                            }
                        }]
                }

  2. I've found the problem. I had in the model something like this:

    Code:
    {
                name: 'ValidUntil', type: 'date', dateFormat: 'd-M-Y',
                convert: function (value) {
                    return value === undefined ? null : new Date(value);
                }
            },
    And when I didn't select a date, the "value" becomes null and the convert function returned new Date(null)

  3. #2
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579
    Answers
    165

    Default

    Can you provide your implementation of onAddClick? Specifying null or an empty value should not set this to 01-01-1970.
    Tristan Lee
    Sencha Inc - Sustaining Engineer


    Having an issue? Help us help you - be detailed; provide some code; demonstrate with a fiddle (fiddle.sencha.com)

    Embed your fiddle in your post: [FIDDLE]id[/FIDDLE]

  4. #3
    Sencha User
    Join Date
    Apr 2015
    Posts
    6
    Answers
    1

    Default

    I've found the problem. I had in the model something like this:

    Code:
    {
                name: 'ValidUntil', type: 'date', dateFormat: 'd-M-Y',
                convert: function (value) {
                    return value === undefined ? null : new Date(value);
                }
            },
    And when I didn't select a date, the "value" becomes null and the convert function returned new Date(null)

  5. #4
    Sencha - Sustaining Engineer tristan.lee's Avatar
    Join Date
    Mar 2015
    Location
    Central Ohio
    Posts
    1,579
    Answers
    165

    Default

    Great, glad you figured it out.
    Tristan Lee
    Sencha Inc - Sustaining Engineer


    Having an issue? Help us help you - be detailed; provide some code; demonstrate with a fiddle (fiddle.sencha.com)

    Embed your fiddle in your post: [FIDDLE]id[/FIDDLE]

Similar Threads

  1. Automatically fill hasone association on loading a model via proxy
    By uncl3t0m in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 19 Nov 2014, 7:13 AM
  2. MysqlDateField: prevents DateField to transform 0000-00-00 to 1970-01-01
    By LorenzoW in forum Ext 2.x: User Extensions and Plugins
    Replies: 6
    Last Post: 26 Jan 2011, 3:10 AM
  3. The problem of datefield Automatically converted
    By backstreet in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 28 Apr 2009, 6:54 PM
  4. [2.2.1] DateField Unable to select 01.01.1970
    By mattpi in forum Ext 2.x: Bugs
    Replies: 3
    Last Post: 3 Apr 2009, 12:37 AM
  5. DateField - 01.01.1970
    By 6epcepk in forum Sencha Ext JS Q&A
    Replies: 3
    Last Post: 15 Jan 2008, 1:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •