如何将表单字段和工具栏按钮居中?

时间:2013-03-08 12:40:00

标签: extjs extjs4.1 extjs-mvc

我在extjs4工作。我正在考虑我想要正确地在中心位置的面板中格式化项目。但我不知道如何。

Here Is my registarion form view

其实我想在中间位置显示所有项目而不是左侧..我也希望在中心位置显示提交按钮,但它会在左侧显示..我正面临这个问题......

这是我的一些代码:

Ext.define('Am.user.Registration',  {
    extend:'Ext.form.Panel',
    //extend:'Ext.window.Window',
    id:'registationId',
    alias:'widget.Registration',
    title:'Registration form',
    resizable:false,
    buttonAlign:'center',
    closable:true,
    titleAlign:'center',
    //autoScroll:true,
    draggable:false,
    //shadow:true,
    height:350,
    width:800,
    floating:true,
    bodyPadding: 30,
    //collapsible:true,
    requires:[
             'Balaee.view.sn.user.Captcha'
              ], 
     defaults:{
        //align:'center'
        defaultAlign:'t1-c'
     },         
     //bodyStyle: 'align:center',        
   // Ext.require(['Ext.form.field.Date']);
    items:[
    {
        xtype:'combo',
        fieldLabel:'Language',
        name:'language',
        emptyText: 'Language',
        store: ['Marathi','Hindi','English'],
        queryMode: 'local',
        editable:false
    }, 
    {
        xtype: 'fieldcontainer',
        fieldLabel: 'Name',
        layout: 'hbox',
        combineErrors: true,
        defaults: {
            hideLabel: true
        },
        items: [
            {xtype: 'textfield',    fieldLabel: 'First', name: 'firstName', emptyText: 'First name',width: 80,  allowBlank: false,margins: '0 5 0 0'},
            {xtype: 'textfield',    fieldLabel: 'Middle', name: 'middleName',emptyText: 'Middle name', width: 80, allowBlank: true, margins: '0 5 0 0'},
            {xtype: 'textfield',    fieldLabel: 'Last', name: 'lastName', emptyText: 'Last name',width: 80, allowBlank: false,
                validator: function(value) {
                    var password1 = this.previousSibling('[name=firstName]');
                    return (!(value === password1.getValue())) ? true : 'Dont give first name and last name same.'
                }                           
            }
        ]
    },
    {
        xtype:'textfield',
        fieldLabel:'Primary email',
        name:'primaryEmail',
        //anchor:'100%',
        allowBlank:false,
        emptyText: 'Email',
        vtype:'email'
        //labelAlign:'right',
    },
    ---------------
    --------------
    ],//End of items square
//  buttons:[{
//      xtype:'button',
//          formBind: true,
//          fieldLabel:'submitttttttt',
//          action:'submitAction',
//          text:'Submit',
//          defaultAlign:'t1-c'
//  }   
//  ],
    bbar:
    [
        {
            xtype:'button',
            formBind: true,
            fieldLabel:'submit',
            action:'submitAction',
            text:'Submit',
            defaultAlign:'t1-c'
            //flex:6,
        },
    ],//End of buttons square
});// End of login class

1 个答案:

答案 0 :(得分:2)

您应该将HBox布局(包装:'center')应用于表单,并同样适用于您的工具栏。

您可以看到如何为表单here执行此操作的示例。对于工具栏:

var toolbar = new Ext.Toolbar({
    dock: 'bottom',
    layout:{
        pack: 'center'
    },
    items: [{
        xtype: 'button',
        text: 'foobar',
        handler: function(){
           alert('ok');
        }
    }]
});