Results 1 to 3 of 3

Thread: Can't get Form to work with localstorage proxy

  1. #1

    Default Can't get Form to work with localstorage proxy

    Hi there,

    one thing is bothering me for days and as we say in Germany: I can't see the wood for the trees

    It's just a simple thing but i can't get it to work. Here's what I've done:

    Versions: Sencha Touch 2.3.1, Architect 3.0.2.1375



    My Client Model:
    Code:
    Ext.define('MyApp.model.Client', {
        extend: 'Ext.data.Model',
    
    
        requires: [
            'Ext.data.Field'
        ],
    
    
        config: {
            identifier: {
                type: 'uuid'
            },
            fields: [
                {
                    allowNull: false,
                    name: 'cid',
                    type: 'string'
                },
                {
                    allowNull: false,
                    name: 'secret',
                    type: 'string'
                },
                {
                    name: 'name',
                    type: 'string'
                },
                {
                    name: 'id'
                }
            ]
        }
    });
    The Store:
    Code:
    Ext.define('MyApp.store.Clients', {
        extend: 'Ext.data.Store',
    
    
        requires: [
            'MyApp.model.Session',
            'Ext.data.proxy.LocalStorage'
        ],
    
    
        config: {
            autoLoad: true,
            autoSync: true,
            model: 'MyApp.model.Session',
            storeId: 'Clients',
            proxy: {
                type: 'localstorage',
                id: 'myapp-client'
            }
        }
    });
    The (Form)panel:
    Code:
    Ext.define('MyApp.view.ConfigurationView', {
        extend: 'Ext.Container',
    
    
        requires: [
            'Ext.form.Panel',
            'Ext.form.FieldSet',
            'Ext.field.Text',
            'Ext.Button',
            'Ext.TitleBar'
        ],
    
    
        config: {
            height: '100%',
            itemId: 'configurationView',
            layout: 'fit',
            scrollable: false,
            items: [
                {
                    xtype: 'formpanel',
                    height: '100%',
                    itemId: 'configurationFormPanel',
                    scrollable: false,
                    items: [
                        {
                            xtype: 'fieldset',
                            title: 'Client',
                            items: [
                                {
                                    xtype: 'textfield',
                                    label: 'Client ID',
                                    name: 'id'
                                },
                                {
                                    xtype: 'textfield',
                                    label: 'Client Passwort',
                                    name: 'secret'
                                },
                                {
                                    xtype: 'button',
                                    itemId: 'configurationSubmit',
                                    ui: 'confirm',
                                    text: 'Submit'
                                }
                            ]
                        },
                        {
                            xtype: 'titlebar',
                            docked: 'top',
                            title: 'Configuration'
                        },
                        {
                            xtype: 'container',
                            html: '<div>Here comes the docs...<div>'
                        }
                    ]
                }
            ]
        }
    
    
    });
    And here's the controller, which doesn't work:

    Code:
    Ext.define('MyApp.controller.ConfigurationsController', {
        extend: 'Ext.app.Controller',
    
    
        config: {
            refs: {
                configurationFormPanel: 'formpanel#configurationFormPanel'
            },
    
    
            control: {
                "button#configurationSubmit": {
                    tap: 'onConfigurationSubmitButtonTap'
                }
            }
        },
    
    
        onConfigurationSubmitButtonTap: function(button, e, eOpts) {
    
    
            var formObj = this.getConfigurationFormPanel();
            var formData = formObj.getValues();
    
    
            console.log(formData.id); //Correctly outputs the values
            console.log(formData.secret); //Correctly outputs the values
    
    
            var clientstore = Ext.data.StoreManager.lookup('Clients').add({
                 "secret": formData.secret,
                 "cid": formData.id
            });
    
    
            console.log(client[0].get('secret')); //returns undefined so no wonder nothing is stored... But why?
    
    
            clientstore.sync();   // Empty localstorage entry appears like: myapp-client-ext-record-3: {"id":"ext-record-3"}
        }
    
    
    });
    I modified values and configuration for hours without getting it to work even it can't be that difficult I think.

    Please help!

  2. #2
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    4,108
    Answers
    342

    Default

    Have you verified that the data exists in localstorage by checking the resources panel in the browser dev tools?
    Get more personalized support via a support subscription.

    Need more help with your app? Hire Sencha Services [email protected]

    When posting code, please use BBCode's CODE tags.

    Need to include a test case use:
    The official Sencha Fiddle

  3. #3
    Sencha Premium User
    Join Date
    Nov 2013
    Posts
    320
    Answers
    9

    Default

    May I ask how the heck the variable "client" would have been created?

    I mean, you defined it nowhere, so "undefined" seems a good fit.

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
  •