Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4 get form Id

Tags:

extjs

I am using Extjs 4.2, The below is the code. I have defined the form Id, but button event can't get the value. the weird thing is, when I submit the form, it will go to server side and I can get the field value.

How to the ID value ?

Ext.define('App.view.QuestionForm',{
    extend      : 'Ext.form.Panel',
    alias       : 'widget.QuestionForm',
    requires    : ['Ext.data.Store'],

    bodyPadding  : 5,  
    defaults  : {xtype  : 'textfield' },

    id: 'question_form',

    initComponent   : function(){
        var me = this;
        //me.id = 'question_form';

        me.items = me.buildItems();
        me.dockedItems = me.buildToolbars();
        me.callParent();
    },


    buildItems : function(){
        return [
        {
            fieldLabel: 'ID',  
            name: 'id',
            xtype: 'textfield', 
            anchor: '100%'
        },        
        ];
    },
    buildToolbars : function(){
        return [{
            xtype : 'toolbar',
            dock: 'top',
            items : [

            {
                xtype: 'button', 
                text:'Save', 
                handler: function(){
                    var form = this.up('form').getForm();
                     console.log("form :"+form.id); //undefined 

                    form.submit({url: 'rs/question/save'});                
                }
            },       


            ]
        }];
    }

});

thanks

like image 933
user595234 Avatar asked Nov 24 '25 15:11

user595234


1 Answers

You define id of the Ext.form.Panel component. So in handler just use:

var form = this.up('form');

for getting instance of the Ext.form.Panel component.

When you call method getForm() of the Ext.form.Panel component it returns underlying Ext.form.Basic component which does not have defined ID.

like image 116
Akatum Avatar answered Nov 26 '25 18:11

Akatum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!