最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ExtJs FormPanel - How to submit form using buttons declared inline? - Stack Overflow

programmeradmin4浏览0评论

I'm getting started with ExtJs. I'm building a very simple login form:

Ext.onReady(function () {

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var loginForm = new Ext.form.FormPanel({
        url: '/Account/Login',
        monitorValid: true,
        labelWidth: 75,
        frame: true,
        title: 'Login',
        width: 250,
        defaultType: 'textfield',
        defaults: { allowBlank: false },

        items:
        [{ fieldLabel: 'Username', name: 'username' },
        { fieldLabel: 'Password', name: 'password', inputType: 'password'}],

        buttons:
        [{
            text: 'Login',
            formBind: true,
            handler: function (btn, evt) { /* how do i submit the form? */ }
        }]

    });

    loginForm.render(document.body);
    loginForm.el.center();
});

As you can see in the login button's handler function, I'm not quite sure how to submit the form. I have been pouring through the API documentation and have found some information about using the FormPanel's internal BasicForm submit method, but I'm not quite sure how to get at it. What am I missing?

I'm getting started with ExtJs. I'm building a very simple login form:

Ext.onReady(function () {

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var loginForm = new Ext.form.FormPanel({
        url: '/Account/Login',
        monitorValid: true,
        labelWidth: 75,
        frame: true,
        title: 'Login',
        width: 250,
        defaultType: 'textfield',
        defaults: { allowBlank: false },

        items:
        [{ fieldLabel: 'Username', name: 'username' },
        { fieldLabel: 'Password', name: 'password', inputType: 'password'}],

        buttons:
        [{
            text: 'Login',
            formBind: true,
            handler: function (btn, evt) { /* how do i submit the form? */ }
        }]

    });

    loginForm.render(document.body);
    loginForm.el.center();
});

As you can see in the login button's handler function, I'm not quite sure how to submit the form. I have been pouring through the API documentation and have found some information about using the FormPanel's internal BasicForm submit method, but I'm not quite sure how to get at it. What am I missing?

Share Improve this question asked Oct 5, 2010 at 16:34 Ronnie OverbyRonnie Overby 46.5k74 gold badges272 silver badges350 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

This works:

Ext.onReady(function () {

    Ext.QuickTips.init();

    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var loginForm = new Ext.form.FormPanel({
        url: '/Account/Login',
        monitorValid: true,
        labelWidth: 75,
        frame: true,
        title: 'Login',
        width: 250,
        defaultType: 'textfield',
        defaults: { allowBlank: false },

        items: [
            { fieldLabel: 'Username', name: 'username' },
            { fieldLabel: 'Password', name: 'password', inputType: 'password'}
        ],

        buttons: [
            {
                text: 'Login',
                formBind: true,
                handler: function (btn, evt) { loginForm.getForm().submit(); }
            }
        ]
    });

    loginForm.render(document.body);
    loginForm.el.center();
});

I didn't do this at first because referencing the formPanel variable while building the object felt weird, but I think it's ok to do it within a callback function.

发布评论

评论列表(0)

  1. 暂无评论