1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    9
    Vote Rating
    0
    smantscheff is on a distinguished road

      0  

    Default Unanswered: Problems with forms, records and sliders

    Unanswered: Problems with forms, records and sliders


    In my app I use a local store for personal patient data and a form where the user can edit their data.
    The problem is that the data in the store are not loaded into the form. The text and slider fields remain at null value when the form is displayed.
    The data are stored in the local store, though, as the Chrome debugger shows. The workaround below for loading the data works, but this is not the way to do it.
    Where am I going wrong?

    Code:
    Ext.define( 'BT.model.Patient', {
        extend: 'Ext.data.Model'
    ,    config: {
            fields: [
                {name: "id", type: "number" /* , default: "1" does not work with samsung} */ }
            ,    {name: "name", type: "string"}
            ,    {name: 'jahre', type: 'number' }
            ,    {name: 'gewicht', type: 'number' }
            ]
        ,    proxy: { 
                type: 'localstorage'
            ,     id: 'Patient' 
            }
        }
    });
    
    Ext.define( 'BT.store.Patient', {
        extend: 'Ext.data.Store'
    ,    requires: ['Ext.data.Store','BT.model.Patient']
    ,    config: {
            id: 'storePatient'
        ,    storeId: 'storePatient'
        ,    model: 'BT.model.Patient'
        ,    autoLoad: true
        ,    autoSync: true
        }
    });
    Ext.create('BT.store.Patient');
    
    
    
    Ext.define('BT.view.Patient', {
        extend: 'Ext.form.Panel'
    ,    requires: ['Ext.field.Slider', 'BT.store.Patient']
    ,    config: {
            id: 'formPatient'
        ,    title: 'Patient'
        ,    fields: ['name','jahre','gewicht']
        ,    iconCls: 'user'
        ,    iconMask: true
        ,    listeners: {
                initialize: function(obj, options) {
                    log( 'initialize...');
                    obj.storePatient = Ext.getStore( 'storePatient' );
                    if (obj.storePatient.data.length == 0) {
                        log('adding...');
                        obj.storePatient.add({id:1,name:'(Name des Kindes)',jahre:'0',gewicht:'0'});
                        obj.storePatient.sync();
                    } 
                    var theRecord = obj.storePatient.getAt(0);
                    log(theRecord);
                    obj.setRecord(theRecord);
                    console.log(obj.getRecord());
    //                obj.getRecord().save();
    // workaround for loading data into theh form
                    obj.getComponent('jahre').setValue(theRecord.get('jahre'));
                    obj.getComponent('name').setValue(theRecord.get('name'));
                    obj.getComponent('gewicht').setValue(theRecord.get('gewicht'));
                }
                    }
        ,    items: 
        [
            {
                xtype: 'toolbar'
            ,    docked: 'top'
            ,    items: [
                        {
                            xtype: 'button'
                        ,    text: 'Weiter'
                        ,    ui: 'forward'
                        ,    docked: 'right'
                        ,    handler: function() {this.getParent().getParent().getParent().setActiveItem(2);}
                        }
                ]
            }    
            ,    
            {
                xtype: 'textfield'
            ,    name: 'name'
            ,    id: 'name'
            ,    label: '$Name'
            ,    cls: 'w100'
            ,    listeners : {
                    change: function (obj, newValue, oldValue, options) { 
                        this.getParent().getRecord().set(this.getName(),this.getValue());
                    }
                }
            }
            , 
            {
                xtype: 'sliderfield'
            ,    name: 'jahre'
            ,    id: 'jahre'
            ,    label: '<div style="float:left">' + '$Alter' + '</div><div class="label_einheit_rechts"><span id="label_alter"></span></div>'
            ,    allowThumbsOverlapping: true
            ,    minValue: 5
            ,    maxValue: 15
            ,    listeners: {
                    change: function (obj, newValue, oldValue, options) { 
                        this.getParent().getRecord().set(this.getName(),this.getValue());
                    }
                ,    drag:     function(obj, slider, thumb, newValue, oldValue) {
                        document.getElementById('label_alter').innerHTML = (newValue > 0 ? newValue + ' ' + '$Jahre' : '');
                    }
                } 
            }
            , 
            {
                xtype: 'sliderfield'
            ,    name: 'gewicht'
            ,    id: 'gewicht'
            ,    label: '<div style="float:left">' + '$Gewicht' + '</div><div class="label_einheit_rechts"><span id="label_gewicht"></span></div>'
            ,    minValue: 5
            ,    maxValue: 70
            ,    listeners: {
                    change: function (obj, newValue, oldValue, options) { 
                        this.getParent().getRecord().set(this.getName(),this.getValue());
                    }
                ,    drag:     function(obj, slider, thumb, newValue, oldValue) {
                        document.getElementById('label_gewicht').innerHTML = (newValue > 0 ? newValue + ' ' + '$kg': '');
                    }
                }
            }
        ] // items
        }
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    So is the issue getting the record? Or apply the values from the record to the form?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

  3. #3
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    Answers
    6
    riyaad is on a distinguished road

      0  

    Default Applying the values from the record to the form?

    Applying the values from the record to the form?


    Hi, this is interesting and more or less what I'm looking for. Im my case, the question is more how does one
    apply the values from the record to the form?

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by riyaad View Post
    Hi, this is interesting and more or less what I'm looking for. Im my case, the question is more how does one
    apply the values from the record to the form?
    The field names in the model has to match the field names in the form. Then you can do

    Code:
    form.setRecord(record)
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

  5. #5
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    Answers
    6
    riyaad is on a distinguished road

      0  

    Default I've done

    I've done


    ...not working =(

    NB: my form contains radio & select fields (shouldn't make a difference though)

    Code:
                    var myForm = Ext.getCmp('form');
                    var store  = Ext.getStore('User');
                    myForm.setRecord(store);
    field names in form matches of my model

    model
    Code:
    Ext.define('MyApp.model.User',{
        extend: 'Ext.data.Model',
    
    
        config: {
            fields:[
                'bouquet',
                'rated',
                'since',
                'age',
                'gender'
            ]
        }
    });
    No errors occur.. Any ideas? I'm know I'm missing something here!

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    The names of the modal and fields match?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

  7. #7
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    Answers
    6
    riyaad is on a distinguished road

      0  

    Default In deed

    In deed


    They match ... (in bold)

    Code:
       config: {
            items: [
                {
                    xtype: 'fieldset',
                    title: 'I am a ...',
                    instructions: 'Change your personal settings as desired.',
                    defaults: {
                        labelAlign: 'left',
                        labelWidth: labelwidth,
                        userClearIcon: true
                    },
                    items: [
                        {
                            xtype: 'radiofield',
                            name: 'gender',
                            label: 'Male:',
                            value: 'male',
                            //checked: true
                        },
                        {
                            xtype: 'radiofield',
                            name: 'gender',
                            label: 'Female:',
                            value: 'female'
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    title: 'who was born in...',
    
    
                    items: [
                        {
                            xtype: 'spinnerfield',
                            id: 'age',
                            name: 'age',
                            minValue: minYear,
                            maxValue: maxYear,
                            increment: 1,
                            cycle: false
                            //value: '1975'
    
    
    
    
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    title: 'and like...',
                    defaults: {
                        xtype: 'selectfield',
                        labelAlign: 'left',
                        labelWidth: labelwidth,
                        userClearIcon: true
                    },
                    items: [
                        {
                            label: 'Bouquet:',
                            name: 'bouquet',
                            valueField: 'bouquet_value',
                            displayField: 'bouquet_name',
                            store: 'Bouquet',
                            value: '7'
                        },
                        {
                            label: 'Movies made since:',
                            name: 'since',
                            valueField: 'since_value',
                            displayField: 'since_name',
                            store: 'Since'
                        },
                        {
                            label: 'Movies rated at least:',
                            name: 'rated',
                            valueField: 'rated_value',
                            displayField: 'rated_name',
                            store: 'Rated'
                        }
                    ]
                },
                {
                    xtype: 'button',
                    text: 'Save',
                    id: 'btnsave',
                    ui: 'confirm',
    
    
                    // Displays a 'Saving...' message
    
    
                    handler: function () {
                        Ext.Viewport.getActiveItem().setMasked({
                            xtype: 'loadmask',
                            message: 'Saving...'
                        });
    
    
                        setTimeout(function() {
                            Ext.Viewport.getActiveItem().setMasked(false);
                        }, 500);
    
    
    
    
                    }
                }
    
    
            ],

  8. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    For radio there is a bug/behavior that the getValue method of the radio/checkbox returns true/null not the actual value. If you override getValue method on the checkbox to return the _value then it should work then.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

  9. #9
    Sencha User riyaad's Avatar
    Join Date
    Jul 2011
    Location
    Cape Town
    Posts
    240
    Vote Rating
    1
    Answers
    6
    riyaad is on a distinguished road

      0  

    Default


    My apologies Mitchell, but could you provide a sample of this "If you override getValue method on the checkbox to return the _value then it should work then." Thank you (really appreciated)

  10. #10
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Here is a quick test case I created

    Code:
    Ext.define('Override.field.Radio', {
        override : 'Ext.field.Radio',
    
        getValue : function() {
            return this._value;
        }
    });
    
    Ext.define('MyModel', {
        extend : 'Ext.data.Model',
    
        config : {
            fields : [
                'gender'
            ]
        }
    });
    
    Ext.application({
        name : 'Test',
    
        launch : function() {
    
            new Ext.form.Panel({
                fullscreen : true,
                items      : [
                    {
                        xtype : 'radiofield',
                        label : 'Male',
                        name  : 'gender',
                        value : 'male'
                    },
                    {
                        xtype : 'radiofield',
                        label : 'Female',
                        name  : 'gender',
                        value : 'female'
                    },
                    {
                        xtype   : 'button',
                        text    : 'Set Record',
                        handler : function(button) {
                            var form   = button.up('formpanel'),
                                record = new MyModel({
                                    gender : 'female'
                                });
            
                            form.setRecord(record);
                        }
                    }
                ]
            });
    
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

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

Thread Participants: 2

Tags for this Thread