Results 1 to 3 of 3

Thread: Adding components to a form dynamically

  1. #1

    Default Adding components to a form dynamically

    I am trying to dynamically add a field to a form when the user presses a button, but I can't really get it to work. This is my code:

    PHP Code:
    Ext.ns('App''App.pagetype');

    App.pagetype.EditForm Ext.extend(Ext.form.FormPanel, {
        
    //frame: true,
        
    title'Properties',

        
    /**
         * initComponent
         * @protected
         */
        
    initComponent : function() {
            
    this.labelAlign 'left';
            
    this.frame true;
            
    this.bodyStyle ='padding:10px 10px 0';

            
    this.items this.buildForm();
            
    this.buttons this.buildUI();

            
    // super
            
    App.pagetype.EditForm.superclass.initComponent.call(this);
        },

        
    buildForm : function() {

            var 
    result = new Array();

                
    result.push([{
                    
    layout:'column',
                    
    items:[{
                        
    columnWidth:.18,
                        
    layout'form',
                        
    items: [{
                                
    xtype:'textfield',
                                
    fieldLabel'Name',
                                
    name'__name',
                                
    anchor:'95%',
                                
    valuei,
                                
    disabledtrue
                        
    }] 
                   }]
               }]);

            }
            return 
    result;
        },

      
        
    buildUI: function(){
            return [{
                
    text'Add property',
                
    iconCls'icon-add',
                
    handlerthis.onCreateNew,
                
    scopethis
            
    }
        },


        
    onCreateNew : function(btnev) {
            
    this.getForm().add({    // This generates the error
                                
    xtype:'textfield',
                                
    fieldLabel'test',
                                
    name'test',
                                
    anchor:'95%',
                                
    value'test',
                                
    disabledtrue
                       
                        
    });
            
    this.getForm().doLayout();
        }
    }); 

    When pressing the button i get the following error: "o.getItemId is not a function". What am I doing wrong?

  2. #2
    Sencha User Eugen_'s Avatar
    Join Date
    Feb 2010
    Posts
    106

    Default

    Quote Originally Posted by moberg View Post
    PHP Code:
            this.getForm().add({    // This generates the error 
    Maybe this.add... ?

    This is from API Documentation:
    You will not usually call this function. In order to be rendered, a Field must be added to a Container, usually an FormPanel. The FormPanel to which the field is added takes care of adding the Field to the BasicForm's collection.

  3. #3

    Default

    haha, that was almost a bit too easy. Too many hours of coding yesterday.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •