javascriptextjsdatefieldextjs6.2timefield

ExtJS - Record changes form's value's format


I have a form with datefield and timefield elements. I edited datefield format to Y-m-d and time output as follows:

    var form = Ext.getCmp('travelForm').getForm();
    var record = form.getRecord();
    var values = form.getValues();

    if (values.hora_inicio!='')
        values.hora_inicio = values.hora_inicio + ':00';
    if (values.hora_termino!='')
        values.hora_termino =  values.hora_termino + ':00';
    if (values.hora_ingreso!='')
        values.hora_ingreso =  values.hora_ingreso + ':00';

    record.beginEdit();
    record.set(values);
    record.endEdit();

    console.log(JSON.stringify(values));

The display of JSON.stringify(values) is my data with correct format, but when I do

record.save()

it fails because the request payload says that the mentioned data (both timefield and datefield values) are ISO dates ('YYYY-mm-dd'T'HH:MM:SS). I'm guessing it has to do with the output of the timefield and datefield elements as objects, but I need orientation on how to change record's format to do a record.save() with the proper outputs.

EDIT

As suggested, I'm including the configuration of both timefield and datefield. They are part of the 'items' config of my form:

                    {
                        xtype: 'datefield',
                        margin: '5 0 0 0',
                        labelWidth: 150,
                        labelSeparator: ' ',
                        submitEmptyText: false,
                        anchor: '100%',
                        format:'Y-m-d',
                        fieldLabel: 'Fecha Inicio',
                        emptyText: 'Fecha Inicio',
                        name:'fecha_inicio',
                        allowBlank: false,
                    },
                    {
                        xtype: 'timefield',
                        minValue: '0:00',
                        maxValue: '23:30',
                        format: 'H:i',
                        increment: 30,
                        anchor: '100%',
                        fieldLabel: 'Hora Inicio',
                        id: 'form_hora_inicio',
                        emptyText: 'Hora Inicio',
                        name:'hora_inicio',
                        allowBlank: false
                    },

The model of this is:

Ext.define('Admin.model.travel.Travel', {
    extend: 'Admin.model.Base',

fields: [
    {
        name: 'nombre'
    },
    {
        name: 'fecha_inicio',
        type: 'string'
    },
    {
        name: 'hora_inicio',
        type: 'string'
    },
    {
        name: 'fecha_termino',
        type: 'string'
    },
    {
        name: 'hora_termino',
        type: 'string'
    }
],
idProperty: 'id_travel',
proxy: {
    type: 'ajax',
    reader: {
        type: 'json',
        rootProperty: 'data'
    },
    api: {
        create  : 'index.php/travel/create_travel',
        //read    : '',
        update  : 'index.php/travel/update_travel',
        destroy : 'index.php/travel/delete_travel'
    }
}
});

Also I can point that if I do

console.log(record.data)

It shows me 2 displays: first, data as JSON which has correct format, and then it shows data again but with all dates converted to ISO format.


Solution

  • If it is of anyone's use, right before

    record.save();
    

    there was a

    form.updateRecord(record);
    

    which caused values of object 'record' to be retrieved again from form, with all kinds of format issues. Commenting that did it for me.