Search code examples
sencha-touchstoreformpanel

Sencha Touch FormPanel With Store


I have a store as follows.

var eventsStore = new Ext.data.Store({
    model: 'Event',
    sorters: [{
        property: 'OccurringOn',
        direction: 'DESC'
    }],
    proxy: {
        type: 'ajax',
        url: BaseURL + 'Events.php',
        api: {
            read: BaseURL + 'Events.php',
            create: BaseURL + 'Events.php'
        },
        reader: {
            type: 'xml',
            root: 'Events',
            record: 'Event'
        },
        writer: {
            type: 'xml',
            writeAllFields: false,
            root: 'Events',
            record: 'Event'
        }
    },
    getGroupString: function(record) {
        if (record && record.data.OccurringOn) {
            console.log(record.get('OccurringOn'));
            return record.get('OccurringOn').toDateString();
        }
        else {
            return '';
        }
    }
});

I also have a List view which gets all Events fine. I have a form which allows user to add new event and I have FormPanel for it. The FormPanel has Toolbar which has Save button which when clicked will do following.

var eventCard = It's a card

var newEventCard = eventCard.items.items[1];

var currentEvent = newEventCard.getRecord();

newEventCard.updateRecord(currentEvent);

var errors = currentEvent.validate();

// here I check errors and prompt user about them

var eventList = eventCard.items.items[0].items.items[0];
var eventStore = eventList.getStore();

eventStore.add(currentEvent);
eventStore.sync();
eventStore.sort( [ { property: 'OccurringOn', direction: 'DESC' } ] );
eventList.refresh();

The above code adds two empty rows to the MySQL database and copies the event list view items with 3 empty new items. Why this is the behavior and what I am missing?

If you can tell me what parameters are sent as POST to the Events.php when I sync that would much appreciated.


Solution

  • It was my fault I figured out. I was echo'ing when there was POST request to the service.