[Form] 【已解决】Form提交问题

[ 4351 查看 / 23 回复 ]

【已解决】Form提交问题
当我用form.getForm().submit()提交时,报错
  1. //ext-all-debug.js 行2407
  2. contains : function(el){
  3.         if(!el){return false;}
  4.         return D.isAncestor(this.dom, el.dom ? el.dom : el);
  5. //Permission denied to access property 'dom' from a non-chrome context
  6.     } //ext-all-debug.js 行28491
  7. isValid : function(){
  8.         var valid = true;
  9.         this.items.each(function(f){
  10.           if(!f.validate()){//f.validate is not a function
  11.               valid = false;
  12.           }
  13.         });
  14.         return valid;
  15.     }
复制代码
我怀疑是Form的控件问题,请教有经验的人士,是什么问题?
最后编辑Astral 最后编辑于 2009-12-04 09:58:04
TOP
【已解决】Form提交问题

你的代码是怎么写的,报的是什么错误
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题

  1. var m_window = new Ext.Window({
  2.     title: '测点信息',
  3.     width: 600,
  4.     height: 600,
  5.     plain: true,
  6.     closeAction: 'hide', //默认动作为“close”,hide仅仅是隐藏了窗体 
  7.     defaults: {
  8.         anchor: '95%'
  9.     },
  10.     layout:'form',
  11.     items: [monitorSpot_form],
  12.     modal: true,
  13.     buttons: [{
  14.         id: 'btn_submit',
  15.         text: '确定',
  16.         handler: function(){
  17.             Ext.MessageBox.show({
  18.                 msg: '正在保存数据, 请稍侯',
  19.                 progressText: '正在保存中',
  20.                 width: 300,
  21.                 wait: true,
  22.                 waitConfig: {
  23.                     interval: 200
  24.                 },
  25.                 icon: 'ext-mb-save',
  26.                 nimEl: 'btn_submit'
  27.             });
  28.            
  29.             monitorSpot_form.getForm().submit({
  30.                 url: 'AddMonitorSpot.aspx?parentID='+parentID,
  31.                 method: 'POST',
  32.                 success: function(form, action){
  33.                     Ext.MessageBox.hide();
  34.                     Ext.MessageBox.alert('提示', '数据保存成功!');
  35.                     m_window.hide();
  36.                     ds.load({
  37.                         params: {
  38.                             start: 0,
  39.                             limit: 25,
  40.                             id:parentID
  41.                         }
  42.                     });
  43.                 },
  44.                 failure: function(form, action){
  45.                     Ext.MessageBox.hide();
  46.                     var message = "";
  47.                     if(action.failureType == 'server'){
  48.                         obj = Ext.util.JSON.decode(action.response.responseText);
  49.                         message = obj.errors.reason;
  50.                     }
  51.                     else{
  52.                         message = action.response.responseText;
  53.                     }
  54.                     Ext.MessageBox.show({
  55.                         title: '错误',
  56.                         msg: message,
  57.                         buttons: Ext.Msg.OK,
  58.                         icon: Ext.MessageBox.ERROR
  59.                     });
  60.                 }
  61.             });
  62.         }
  63.     }, {
  64.         text: '取消',
  65.         handler: function(){
  66.             m_window.hide();
  67.         }
  68.     }]
  69. });
复制代码
报错就是上面哪两个错
最后编辑Astral 最后编辑于 2009-12-02 11:04:08
TOP
【已解决】Form提交问题

我感觉和你交流这么费事呢,我问你报的什么错,没问你在哪报的错
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题

还有,你的代码没有关于form的定义。
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题


TOP
【已解决】Form提交问题

  1. var monitorSpot_form = new Ext.FormPanel({
  2.     labelWidth:75,
  3.     url:'AddMonitorSpot.aspx',
  4.     frame:true,
  5.     bodyStyle:'padding:5px 5px 0;width:95%',
  6.    
  7.     items:[{
  8.         //设备位置码
  9.         id:'MonitorSpotCodeInfo',
  10.         xtype:'fieldset',
  11.         checkboxToggle:true,
  12.         title:'设备位置码',
  13.         autoHeight:true,
  14.         collapsed:true,
  15.         items:
  16.         [{
  17.             layout:'column',
  18.             items:
  19.             [{
  20.                 columnWidth:.5,
  21.                 layout: 'form',
  22.                 items: [{
  23.                     xtype:'label',
  24.                     fieldLabel: '设备',
  25.                     name: 'Eq_Code',
  26.                     isFormField:true,
  27.                     anchor:'85%'
  28.                 }]
  29.             },
  30.             {
  31.                 columnWidth:.5,
  32.                 layout: 'form',
  33.                 items: [{
  34.                     xtype:'textfield',
  35.                     fieldLabel: '测      点',
  36.                     name: 'MS_Code',
  37.                     anchor:'85%'
  38.                 }]
  39.             }]
  40.         }]
  41.     },{
  42.         //基本信息
  43.         id:'MonitorSpotBaseInfo',
  44.         xtype:'fieldset',
  45.         checkboxToggle:true,
  46.         title:'基本信息',
  47.         autoHeight:true,
  48.         collapsed:false,
  49.         items:
  50.         [{
  51.             layout:'column',
  52.             items:
  53.             [{
  54.                 columnWidth:.5,
  55.                 layout: 'form',
  56.                 items: [{
  57.                     xtype:'textfield',
  58.                     fieldLabel: '测点名称',
  59.                     name: 'MS_Name',
  60.                     anchor:'85%'
  61.                 },{
  62.                     xtype:'combo',
  63.                     fieldLabel: '监测方式',
  64.                     name: 'MS_InspectMode',
  65.                     store:inspectMode_store,
  66.                     emptyText:'请选择',
  67.                     mode:'local',
  68.                     triggerAction:'all',
  69.                     valueField:'value',
  70.                     displayField:'text',
  71.                     readOnly:true,
  72.                     anchor:'85%'
  73.                 }]
  74.             },
  75.             {
  76.                 columnWidth:.5,
  77.                 layout: 'form',
  78.                 items: [{
  79.                     xtype:'combo',
  80.                     fieldLabel: '工程单位',
  81.                     name: 'MS_EngUnit',
  82.                     store:engUnit_store,
  83.                     emptyText:'请选择',
  84.                     mode:'remote',
  85.                     triggerAction:'all',
  86.                     valueField:'EU_Unit',
  87.                     displayField:'EU_Name',
  88.                     readOnly:true,
  89.                     anchor:'85%'
  90.                 },{
  91.                     xtype:'numberfield',
  92.                     fieldLabel: '检测周期',
  93.                     name: 'MS_InspectCycle',
  94.                     anchor:'85%'
  95.                 }]
  96.             }]   
  97.         }]
  98.     },{
  99.         //报警信息
  100.         id:'MonitorSpotAlarmInfo',
  101.         xtype:'fieldset',
  102.         checkboxToggle:true,
  103.         title:'报警信息',
  104.         autoHeight:true,
  105.         collapsed:false,
  106.         items:
  107.         [{
  108.             layout:'column',
  109.             items:
  110.             [{
  111.                 columnWidth:.5,
  112.                 layout: 'form',
  113.                 items: [{
  114.                     xtype:'combo',
  115.                     fieldLabel: '报警类型',
  116.                     name: 'MS_AlarmType',
  117.                     store:alarmType_store,
  118.                     emptyText:'请选择',
  119.                     mode:'local',
  120.                     triggerAction:'all',
  121.                     valueField:'value',
  122.                     displayField:'text',
  123.                     readOnly:true,
  124.                     anchor:'85%'
  125.                 },{
  126.                     xtype:'numberfield',
  127.                     fieldLabel: ' 警 戒 值',
  128.                     name: 'MS_Alarm',
  129.                     anchor:'85%'
  130.                 },{
  131.                     xtype:'numberfield',
  132.                     fieldLabel: ' 报 警 值',
  133.                     name: 'MS_Danger',
  134.                     anchor:'85%'
  135.                 }]
  136.             },
  137.             {
  138.                 columnWidth:.5,
  139.                 layout: 'form',
  140.                 items: [{
  141.                     xtype:'numberfield',
  142.                     fieldLabel: ' 参 考 值',
  143.                     name: 'MS_ReferenceVal',
  144.                     anchor:'85%'
  145.                 },{
  146.                     xtype:'numberfield',
  147.                     fieldLabel: '低线警戒',
  148.                     name: 'MS_LowAlarm',
  149.                     anchor:'85%'
  150.                 },{
  151.                     xtype:'numberfield',
  152.                     fieldLabel: '低线报警',
  153.                     name: 'MS_LowDanger',
  154.                     anchor:'85%'
  155.                 }]
  156.             }]   
  157.         }]
  158.     },{
  159.         //高级信息
  160.         id:'MonitorSpotAdvanceInfo',
  161.         xtype:'fieldset',
  162.         checkboxToggle:true,
  163.         title:'高级信息',
  164.         autoHeight:true,
  165.         collapsed:true,
  166.         items:
  167.         [{
  168.             layout:'column',
  169.             items:
  170.             [{
  171.                 columnWidth:.5,
  172.                 layout: 'form',
  173.                 items: [{
  174.                     xtype:'combo',
  175.                     fieldLabel: '安装位置',
  176.                     name: 'MS_Place',
  177.                     store:place_store,
  178.                     emptyText:'请选择',
  179.                     mode:'local',
  180.                     triggerAction:'all',
  181.                     valueField:'value',
  182.                     displayField:'text',
  183.                     readOnly:true,
  184.                     anchor:'85%'
  185.                 },{
  186.                     xtype:'combo',
  187.                     fieldLabel: '专      业',
  188.                     name: 'MS_Profession',
  189.                     store:profession_store,
  190.                     emptyText:'请选择',
  191.                     mode:'local',
  192.                     triggerAction:'all',
  193.                     valueField:'value',
  194.                     displayField:'text',
  195.                     readOnly:true,
  196.                     anchor:'85%'
  197.                 }]
  198.             },
  199.             {
  200.                 columnWidth:.5,
  201.                 layout: 'form',
  202.                 items: [{
  203.                     xtype:'combo',
  204.                     fieldLabel: '监测等级',
  205.                     name: 'MS_Rank',
  206.                     store:rank_store,
  207.                     emptyText:'请选择',
  208.                     mode:'local',
  209.                     triggerAction:'all',
  210.                     valueField:'value',
  211.                     displayField:'text',
  212.                     readOnly:true,
  213.                     anchor:'85%'
  214.                 },{
  215.                     xtype:'numberfield',
  216.                     fieldLabel: '转      速',
  217.                     name: 'MS_Rating',
  218.                     anchor:'85%'
  219.                 }]
  220.             }]   
  221.         }]
  222.     },{
  223.         //备注
  224.         id:'MonitorSpotRemarkInfo',
  225.         xtype:'fieldset',
  226.         checkboxToggle:true,
  227.         title:'备注',
  228.         autoHeight:true,
  229.         collapsed:true,
  230.         layout: 'form',
  231.         items:[{
  232.             xtype:'htmleditor',
  233.             fieldLabel:'备注',
  234.             name:'MS_Remark',
  235.             isFormField:false,
  236.             height:'100'
  237.         }]
  238.     }]
  239. });
复制代码
TOP
【已解决】Form提交问题

你写的这个在Extjs3.0里应该是可以正常运行的,但你引的包是2.2,在2.2与3.0之间,还是有些差别的。你可以试一下把 label里定义的isFormField去掉看看 还报错不
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题

2.2和3.0能完全兼容吗,可以的话,我干脆换了算了
TOP
【已解决】Form提交问题

这个我真的不清楚,没有用过3.0,哈哈。没有实践所以没有发言权
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题

真的是这个问题,果真是控件的问题,谢谢了
TOP
【已解决】Form提交问题

这只是一种方式,还有别的方式可以解决这个问题。一个问题的解决办法可能有很多种,哈哈
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题

isFormField 在2.2中是什么?
TOP
【已解决】Form提交问题

我给你讲讲原理吧 并不是所有formpanel的items都会成为basicform的items,一般来讲只有Ext.form.Field以及其子类或子类的子类....才会被加到basicform里边,因为basicform要依据本身的items进行查找和校验。 这就会涉及到一个从formpanel中找出符合basicform的items,并加入到basicform里的一个方法。

2.2和3.0对于这个方法的处理方式不一样,帖源码看看
2.2的Ext.form.FormPanel里的 initFields方法的定义

initFields : function(){
        var f = this.form;
        var formPanel = this;
        var fn = function(c){
            if(c.isFormField){
                f.add(c);
            }else if(c.doLayout && c != formPanel){
                Ext.applyIf(c, {
                    labelAlign: c.ownerCt.labelAlign,
                    labelWidth: c.ownerCt.labelWidth,
                    itemCls: c.ownerCt.itemCls
                });
                if(c.items){
                    c.items.each(fn);
                }
            }
        }
        this.items.each(fn);
    },

Extjs3.0 Ext.form.FormPanel的initFields方法的定义

initFields : function(){
        var f = this.form;
        var formPanel = this;
        var fn = function(c){
            if(formPanel.isField(c)){
                f.add(c);
            }if(c.isFieldWrap){
                Ext.applyIf(c, {
                    labelAlign: c.ownerCt.labelAlign,
                    labelWidth: c.ownerCt.labelWidth,
                    itemCls: c.ownerCt.itemCls
                });
                f.add(c.field);
            }else if(c.doLayout && c != formPanel){
                Ext.applyIf(c, {
                    labelAlign: c.ownerCt.labelAlign,
                    labelWidth: c.ownerCt.labelWidth,
                    itemCls: c.ownerCt.itemCls
                });
                //each check required for check/radio groups.
                if(c.items && c.items.each){
                    c.items.each(fn, this);
                }
            }
        };
        this.items.each(fn, this);
    },
(Love me) && (Love my bug);
TOP
【已解决】Form提交问题

什么办法可以隐藏fieldLabel,或者显示Label的fieldLabel
TOP