перехватывать HTML-форму и значения с помощью ExtJ - PullRequest
2 голосов
/ 27 августа 2010

Я пытаюсь перехватить отправку формы для создания Ajax-запроса во Viewport с использованием ExtJS.Некоторые формы не имеют имени (или не Id), и во многих случаях кнопка отправки была изменена простой кнопкой.

case 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>

case 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
       }  

   },    

Заранее спасибо за помощь

Ответы [ 2 ]

1 голос
/ 28 августа 2010

Я понял, решение было ...

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 голос
/ 27 августа 2010

Algoritm:

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
...