Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      0  

    Default Answered: Form data not saving to store (does get updated in list view)

    Answered: Form data not saving to store (does get updated in list view)


    Been trying to get this working for a while (well, more like getting the form working), when i finally got it all working and gave the store a new id to test from scratch, i found out i can't add a new entry/record to the store unless i have had an existing record loaded into the form, nor can i use the "phantom" to check whether the record is new or existing. It must be something small I am doing wrong, but have been staring at it too long and can't figure out where the problem is. If anyone could point out what i am doing wrong, i would appreciate it. below is my code.

    Code:
    app.views.PlaceOrder = new Ext.extend(Ext.form.FormPanel, {
        id: 'orderForm',
        scroll: 'vertical',
        items: [
                {
                    xtype: 'panel',
                    dock: 'top',
                    layout: {
                        type: 'hbox',
    //                    align: 'stretch',
                        flex: 1
                    },
    //                    height: '10%',
                    defaults: {
                        xtype: 'button',
                        ui: 'small',
                        iconMask: true
                    },
                    items: [
                            {
    //                            iconCls: 'arrow_up',
                                ui: 'back',
                                listeners: {
                                    'tap': function() {
                                        var form = Ext.getCmp('orderForm');
                                        Ext.dispatch({
                                            controller: app.controllers.customer,
                                            action: 'load',
                                            next: 0,
    //                                        id: index,
                                            data: form.getValues(),
                                            record: form.getRecord()
                                        })
                                    }
                                }
                            },
                            {
                                xtype: 'spacer',
                            },
                            {
    //                            iconCls: 'arrow_down',
                                ui: 'forward',
                                listeners: {
                                    'tap': function() {
                                        var form = Ext.getCmp('orderForm');
                                        Ext.dispatch({
                                            controller: app.controllers.customer,
                                            action: 'load',
                                            next: 1,
    //                                        id: index,
                                            data: form.getValues(),
                                            record: form.getRecord()
                                        })
                                    }
                                }
                            },
                            {
                                xtype: 'spacer',
                            },
                            {
                                iconCls: 'action',
                                ui: 'confirm',
                                listeners: {
                                    'tap': function() {
                                        var form = Ext.getCmp('orderForm');
                                        Ext.dispatch({
                                            controller: app.controllers.customer,
    action: (form.getRecord().phantom ? 'update' : 'save'),
    //action: 'save',
                                            data: form.getValues(),
                                            record: form.getRecord()
                                        })
                                    }
                                }
                            },
                            {
                                xtype: 'spacer',
                            },
                            {
                                iconCls: 'empty2',
                                listeners: {
                                    'tap': function() {
                                        var form = Ext.getCmp('orderForm');
                                        form.reset();
                                    }
                                }
                            },
                            {
                                xtype: 'spacer',
                            },
                            {
                                iconCls: 'list',
                                listeners: {
                                    'tap': function() {
                                        app.views.viewport.setActiveItem(
                                                app.views.customerList
                                        );
                                    }
                                }
                            },
                    ]
                },
                {
                    xtype: 'textfield',
                    name: 'first',
                    label: 'First'
                },
                {
                    xtype: 'textfield',
                    name: 'last',
                    label: 'Last'
                },
                {
                    xtype: 'emailfield',
                    name: 'email',
                    label: 'Email'
                },
                {
                    xtype: 'numberfield',
                    name: 'phone',
                    label: 'Phone'
                },
                {
                    xtype: 'textfield',
                    name: 'address',
                    label: 'Address'
                },
                {
                    xtype: 'textfield',
                    name: 'zipcode',
                    label: 'Zip code'
                },
                {
                    xtype: 'textfield',
                    name: 'city',
                    label: 'City',
                    text: 'Amsterdam'
                },
        ],
        populateForm: function(record) {
            this.load(record);
        },
        initComponent: function() {
            app.views.PlaceOrder.superclass.initComponent.apply(this, arguments);
            // check in usersettings if there is already a default delivery address, if not, do below
            var model = new app.models.CustomerData();
            this.load(model);
        }
    });
    Code:
    app.controllers.customer = new Ext.Controller({
        add: function(values) {
        },
        load: function(values) {
            var loadId;
            values.record.set(values.data);
            if (values.next == 1) {
                loadId = values.record.data.id + 1;
            } else if (values.next == 0) {
                loadId = values.record.data.id - 1;
            } else {
                loadId = values.id;
            }
            var record = app.stores.customer.getById(loadId);
            if (record) {
                app.views.placeOrder.populateForm(record);
            }
        },
        edit: function(values) {
            var record = app.stores.customer.getAt(values.id);
            if (record) {
                app.views.placeOrder.populateForm(record);
            }
    //        app.views.viewport.setActiveItem(app.views.orderForm);
        },
        save: function(params) {
            params.record.set(params.data);
    // check if record id exists already, because phantom check always results in save
            if (app.stores.customer.findRecord('id', params.record.data.id) === null) {
    //Ext.Msg.alert('save/create: ' + params.data.id)
                app.stores.customer.create(params.data);
            } else {
                //Ext.Msg.alert('save/save: ' + params.data.id)
                params.record.save();
            }
            app.stores.customer.sync();
        },
        update: function(params) {
    //Ext.Msg.alert('update: ' + params.data.id)
            params.record.set(params.data);
            params.record.save();
            app.stores.customer.sync();
        }
    });
    Code:
    app.models.CustomerData = Ext.regModel('app.models.CustomerData', {
        idProperty: 'id',
        fields: [
                 {name: 'id', type: 'int'},
                 {name: 'first', type: 'string'},
                 {name: 'last', type: 'string'},
                 {name: 'email', type: 'strign'},
                 {name: 'phone', type: 'string'},
                 {name: 'address', type: 'string'},
                 {name: 'zipcode', type: 'string'},
                 {name: 'city', type: 'string'}
            ]
    });
    
    app.stores.customer = new Ext.data.Store({
        model: 'app.models.CustomerData',
        proxy: {
            type: 'localstorage',
            id: 'customers-test'
        }
    });

  2. got it all working now, although i am not sure which of the changes fixed what.

    phantom didn't work because i had it the other way around, should have been "action: (form.getRecord().phantom ? 'save' : 'update')"

    i moved "proxy: { type: 'localstorage', id: 'customers-test3' }" to the model definition instead of the store. The screencast "Working with forms" had it this way, but in other tutorials/screencasts it was in the store definition. Is that because it is a localstorage?

    added "autoLoad: true" to the store definition, though i still had to use store.load() to update the list after changing records.

    I had a reset button to empty the fields of the form, but if i had loaded a record in it before it would update that record instead of creating a new one. so i added creating a new instance of the model en loaded that after resetting the form.

    not sure which one or combination of those fixed the problem. but at least it works now.

  3. #2
    Touch Premium Member
    Join Date
    Nov 2011
    Location
    Massachusetts
    Posts
    43
    Vote Rating
    0
    martincf is on a distinguished road

      0  

    Default


    I think you may be missing the part where you create an instance of your Model to create the new record. In my save method I have something like the following...
    Code:
    var record = Ext.ModelMgr.create({
                    MyModelLine1: MyValueHere1,
                    MyModelLine2: MyValueHere2
                    },'MyModel'
                );
    
    MyStore.add(record);
    MyStore.sync(record);
    Martin

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      0  

    Default


    I was under the impression that once i had loaded an empty instance of the model into the form (before filling it in), sencha touch no longer needs you to specify it when saving.

  5. #4
    Touch Premium Member
    Join Date
    Nov 2011
    Location
    Massachusetts
    Posts
    43
    Vote Rating
    0
    martincf is on a distinguished road

      0  

    Default


    I work off of example code I find. I'm not sure if I'm always following the Sencha way of doing things. In the examples I found, the form is blank and unloaded(?) and then you populate the new record you are going to add to the store. I guess the question I would ask is, why create the record if you aren't sure the user will ever complete it and save it? I'll admit that I didn't fully analyze your code. Perhaps you have found another way to do it that I'm not aware of nor have seen an example of.

    This is probably the code I got my ideas from. It shows the flow that I use for creating new records.
    http://miamicoder.com/2011/writing-a-sencha-touch-application-part-3/

    M
    artin

  6. #5
    Touch Premium Member
    Join Date
    Nov 2011
    Location
    Massachusetts
    Posts
    43
    Vote Rating
    0
    martincf is on a distinguished road

      0  

    Default


    Looking over this code again, I think it may be using something closer to what you are doing. It appears to create a record partially filled out, loads it into the form and then calls the add function of the store in the save method. I guess I can't remember what made me decide to go the direction I did, but I don't create the record when the form loads up. I create my record on save. There must have been another example I was using, because that would not have been a decision I would have made on my own.

    I'm still learning Sencha Touch myself.

    Martin

  7. #6
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      0  

    Default


    i've never been much into javascript and this is the first app i write with sencha touch/phonegap. So i'm pretty green too. I tried several approaches creating the form and getting the functionality to work and this is what finally actually worked, well almost worked. The method you are using is a bit simpler, but doesn't make use of all the power and convenience of sencha touch. I am trying to do things the way they should be done, whereas i normally just hack things together until they work. i know your way works, but then i may not be able to use the phantom property and need to do a manual check (well, actually already doing that) and such.still hoping someone can point out what i am doing wrong.

  8. #7
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      0  

    Default


    got it all working now, although i am not sure which of the changes fixed what.

    phantom didn't work because i had it the other way around, should have been "action: (form.getRecord().phantom ? 'save' : 'update')"

    i moved "proxy: { type: 'localstorage', id: 'customers-test3' }" to the model definition instead of the store. The screencast "Working with forms" had it this way, but in other tutorials/screencasts it was in the store definition. Is that because it is a localstorage?

    added "autoLoad: true" to the store definition, though i still had to use store.load() to update the list after changing records.

    I had a reset button to empty the fields of the form, but if i had loaded a record in it before it would update that record instead of creating a new one. so i added creating a new instance of the model en loaded that after resetting the form.

    not sure which one or combination of those fixed the problem. but at least it works now.

Thread Participants: 1