layout - 表单水平居中按钮

标签 layout extjs

有人可以帮助我将按钮水平居中吗?我不知道如何提供一个将中心对齐到按钮项目的 vbox 布局。

以下代码来自Sencha Docs .

Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
width: 350,

// The form will submit an AJAX request to this URL when submitted
url: 'save-form.php',

// Fields will be arranged vertically, stretched to full width
layout: 'anchor',
defaults: {
    anchor: '100%'
},

// The fields
defaultType: 'textfield',
items: [{
    fieldLabel: 'First Name',
    name: 'first',
    allowBlank: false
},{
    fieldLabel: 'Last Name',
    name: 'last',
    allowBlank: false
}],

// Reset and Submit buttons
buttons: [{
    text: 'Reset',
    handler: function() {
        this.up('form').getForm().reset();
    }
}, {
    text: 'Submit',
    formBind: true, //only enabled once the form is valid
    disabled: true,
    handler: function() {
        var form = this.up('form').getForm();
        if (form.isValid()) {
            form.submit({
                success: function(form, action) {
                   Ext.Msg.alert('Success', action.result.msg);
                },
                failure: function(form, action) {
                    Ext.Msg.alert('Failed', action.result.msg);
                }
            });
        }
    }
}],
renderTo: Ext.getBody()
});

非常感谢您的支持!

亲切的问候,舒布

最佳答案

我找到了正确的解决方案。您只需将“buttonAlign”配置设置为居中。

Ext.create('Ext.form.Panel', {
    title: 'Simple Form',
    bodyPadding: 5,
    width: 350,

    // The form will submit an AJAX request to this URL when submitted
    url: 'save-form.php',

    // Fields will be arranged vertically, stretched to full width
    layout: 'anchor',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'First Name',
        name: 'first',
        allowBlank: false
    },{
        fieldLabel: 'Last Name',
        name: 'last',
        allowBlank: false
    }],
    buttonAlign: 'center',

    // Reset and Submit buttons
    buttons: [{
        text: 'Reset',
        handler: function() {
            this.up('form').getForm().reset();
        }
    }, {
        text: 'Submit',
        formBind: true, //only enabled once the form is valid
        disabled: true,
        handler: function() {
            var form = this.up('form').getForm();
            if (form.isValid()) {
                form.submit({
                    success: function(form, action) {
                       Ext.Msg.alert('Success', action.result.msg);
                    },
                    failure: function(form, action) {
                        Ext.Msg.alert('Failed', action.result.msg);
                    }
                });
            }
        }
    }],
    renderTo: Ext.getBody()
});

关于layout - 表单水平居中按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9956531/

相关文章:

html - 网页右侧出现奇怪的空白

layout - Laravel jetstream惯性持久布局

javascript - 如何在 Sencha Touch 应用程序中的不同列或框中创建两个列表?

javascript - EXTJS GRID 和存储

node.js - Ext.Direct 文件上传 - 回调 - 错误 "Blocked a frame with origin"

html - 定位图像以与背景无缝融合时出现问题

java - 图形用户界面 : how to properly set layout

extjs - 新记录会获得自动生成的 id 值。如何像 ExtJs 4 中那样获取 0 作为新 id?

asp.net - 分机JS 4 : JavaScript Exception "TypeError: Ext.resetElement is undefined" in Ext JS version 4. 1.1

Android - 如何使用 XML 在不同屏幕密度的特定位置放置按钮