单击提交按钮时提交表单

时间:2011-08-15 17:16:36

标签: extjs modx

我正在尝试在单击按钮时提交表单,但它并不像我想象的那么简单,我总是得到一个 fp.getForm 不是一个函数,虽然提交处理程序直接来自ExtJs文档,任何线索?

Players.panel.Subscription = function(config) {
    config = config || {};
    Ext.apply(config,{
        border: false
        ,baseCls: 'modx-formpanel'
        ,process: 'mgr/player/getSubscribers'
        ,standardSubmit: true
        ,url: Players.config.connectorUrl
        ,baseParams: { action: 'mgr/player/getSubscribers' }
        ,buttons: [{
                    text: 'Export er'
                    ,formBind: true
                    ,type: 'submit'
                    ,handler: function(){


                            var fp = this.ownerCt.ownerCt,
                                form = fp.getForm();
                            if (form.isValid()) {
                                // check if there are baseParams and if
                                // hiddent items have been added already
                                if (fp.baseParams && !fp.paramsAdded) {
                                    // add hidden items for all baseParams
                                    for (i in fp.baseParams) {
                                        fp.add({
                                            xtype: 'hidden',
                                            name: i,
                                            value: fp.baseParams[i]
                                        });
                                    }
                                    fp.doLayout();
                                    // set a custom flag to prevent re-adding
                                    fp.paramsAdded = true;
                                }
                                form.submit();
                            }

                }
                }]

    });
    Players.panel.Subscription.superclass.constructor.call(this,config);

};

我还尝试将基类从 modx-formpanel 替换为 formpanel basicform ,但没有成功。

由于

1 个答案:

答案 0 :(得分:0)

这是因为你没有表格面板。试试这个:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="./ext/resources/css/ext-all.css" />
<script type="text/javascript" src="./ext/bootstrap.js"></script>
</head>
<body>
<script>
Ext.ns('Players.panel');
Ext.onReady(function() {  
  Players.panel.Subscription = Ext.extend(Ext.form.Panel, {
    constructor : function(config) {
      config = Ext.apply({
          border: false
            ,baseCls: 'modx-formpanel'
            ,process: 'mgr/player/getSubscribers'
            ,standardSubmit: true
            ,url: '-'
            ,baseParams: { action: 'mgr/player/getSubscribers' }
            ,buttons: [{
                        text: 'Export er'
                        ,formBind: true
                        ,type: 'submit'
                        ,handler: function(){


                                var fp = this.ownerCt.ownerCt,
                                    form = fp.getForm();
                                if (form.isValid()) {
                                    // check if there are baseParams and if
                                    // hiddent items have been added already
                                    if (fp.baseParams && !fp.paramsAdded) {
                                        // add hidden items for all baseParams
                                        for (i in fp.baseParams) {
                                            fp.add({
                                                xtype: 'hidden',
                                                name: i,
                                                value: fp.baseParams[i]
                                            });
                                        }
                                        fp.doLayout();
                                        // set a custom flag to prevent re-adding
                                        fp.paramsAdded = true;
                                    }
                                    form.submit();
                                }

                    }
                    }]
       }, config);
        Players.panel.Subscription.superclass.constructor.call(this,config);
    }
  });

  var f = Ext.create(Players.panel.Subscription, {id:'formPanel', renderTo: Ext.getBody()});;
});
</script>
</body>
</html>