Why does store.save() not work inside form.submit() success function?

64 Views Asked by At

The form.submit works and saves the data successfully but the store.save does not. I have tried the store.save outside of the form.submit and it works fine, but it needs to be inside as I need to get the id from response.

This is the code:

form.submit({
    success: function (form, response) {
        var id = Ext.decode(response.response.responseText).id;
        if (store.getUpdatedRecords().length > 0) {
            var records = store.getRange();
            Ext.each(records, function (record) {
                record.data.businessCategoryId = id;
            });
            store.save();
        }
     }
});

This is my viewModel including the store:

Ext.define('CustomFit.view.baseData.category.upsert.translations.TranslationsModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.categoryUpsertTranslations',
    stores: {
        translations: {
            proxy: {
                type: 'ajax',
                reader: {
                    type: 'json',
                    rootProperty: 'data'
                },
                api: {
                    read: '../api/language/categorytranslations',
                    update: '../api/language/categorytranslations/save'
                },
                writer: {
                    encode: false,
                    writeAllFields: true,
                    allowSingle: false
                }
            }
        }
    }
});

For some reason the request is getting aborted? This is a screenshot of the network showing the request being aborted.

Any ideas why this is happening or if I'm missing something?

0

There are 0 best solutions below