2010-08-26 48 views
2

我试图拦截提交的表单,以便在使用ExtJS的视口中创建Ajax请求。有些表单没有名称(或不是Id),在很多情况下,提交按钮已被一个简单的按钮更改。用ExtJs拦截HTML表单和值

的情况下1:

<form action="?m=pros&a=add" method="post"> 
    <input type="hidden" name="project_type value='software'> 
    <input type="submit" class="button" value="Add Project"/> 
</form> 

情况下2

<form action="?m=pros&a=edit" method="post"> 
    <input type="button" class="button" value="Edit Project" 
    onclick="javascript:doTheSubmitting(this) 
    /> 
</form> 

我在我的javascript代码预先

initEvents : function(){ 
     contentPanel.superclass.initEvents.call(this); 
     this.body.on('click', this.myClick, this); 
    }, 

    myClick: function(e, target){ 
     /*handler for intercept click over link, submit, buttons*/ 

     //first issue: how to identify: link, button, submit 

     targeIstLink = e.getTarget('a:not(.exi)', 3); //target is a Link 
     targetIsForm = target.form;     //target is a form???? 

     e.stopEvent(); 

     /*solved*/ 
     if(targetIsLink){ 
      //code to ajaxify a link and 
      //load it in the viewport pannel 
     }else 

     /*not solved*/ 
     if(targetIsForm){ 
      //code to ajaxify a form and load it in the panel ViewPort 
     }else 
     if(targetIsFileUpload) { /*coding*/ 
      //code here 
     } 

    },  

THKS的帮助

+0

能否请您详细阐述您的问题吗?并带有示例代码?在没有片段的情况下理解问题变得非常困难。 – Swar 2010-08-27 07:32:44

回答

1

我弄明白,解决方案在那里......

initEvents : function(){ 
    contentPanel.superclass.initEvents.call(this); 

    //This intercept any click in my application 
    this.body.on('click', this.myClicksHandler, this); 

    //Once handled the clicks, intercept submits 
    this.body.on('submit', this.myBeforeSubmittingHandler, this); 
}, 

myClicksHandler: function(e, target){ 
//code here 
}, 

myBeforeSubmittingHandler: function(e, target){ 

} 
1

ALG oritm:

switch(link) 

    1. link.parent is a Form Object?    /*Parent of a submit button*/ 
     1.1 if True, 
      newLink = serialize(Form Object) /*No Break clause*/ 
    2. newLink = formatLinkAsYouLike(link)  /*In the case of a link nodeTag='A' */ 
    Default:          /*both cases */ 
     a) .load(newLink, Params) 
     b) handle whatever you want: onSubmit, onSuccess, onError, onEtcetera 

end Switch 
+0

谢谢Thau。 我找到了通过提交操作识别的解决方案;但仍在争取如何发送 - 使用ajax--表单并将响应分配给Tab。当我收到响应302收​​到错误时,表单隐藏了字段,只有一个按钮发送隐藏值。 – vPJ 2010-08-28 14:53:35