2 Replies Latest reply on May 27, 2008 10:35 AM by Kerdudou Ronan

    menuItem onsubmit doesn't fire

    Kerdudou Ronan Apprentice

      With the folowing code :

      <h:form id="formEntete" onsubmit="return validerForm(this);">
       <rich:toolBar styleClass="table_menu">
       <rich:dropDownMenu value="menu1">
       <rich:menuItem submitMode="server"
       value="test1"
       action="go_test1"/>
       <rich:menuItem submitMode="server"
       value="test2"
       action="#{handler.action}"/>
       </rich:dropDownMenu>
       </rich:toolBar>
      </h:form>
      the onsubmit is never executed.
      when I search in generated html code, I see :
      onclick="this.className='dr-menu-item dr-menu-item-enabled rich-menu-item rich-menu-item-enabled ';
      {var form = A4J.findForm(this);var params = new Object();
       params['formEntete:j_id_jsp_171382336_2pc4:hidden'] = 'formEntete:j_id_jsp_171382336_2pc4';
       Richfaces.jsFormSubmit('formEntete:j_id_jsp_171382336_2pc4',form.id,'',params);
      };
      return false;;"
      and in richfaces forms.js.jsf :
      Richfaces.jsFormSubmit = function(linkId, formName, target, params) {
       var form = document.getElementById(formName);
       if (form) {
       var formTarget = form.target;
       var paramNames = new Array();
       if (params) {
       for (var n in params) {
       paramNames.push(n);
       }
       }
       _JSFFormSubmit(linkId,formName,target,params);
       _clearJSFFormParameters(formName, formTarget, paramNames);
       }
      }
      and then in a4j forms.js.jsf :
      function _JSFFormSubmit(linkId,formName,target,parameters){
       var form = document.getElementById(formName);
       if(form){
       /*var hiddenField = form.elements[formName+":_idcl"];
       if(hiddenField){
       hiddenField.value=linkId;
       } else {
       var input = document.createElement("input");
       input.type="hidden";
       input.name=formName+":_idcl";
       input.value=linkId;
       form.appendChild(input);
       }*/
      
       var paramNames = [];
      
       if(target){
       form.target=target;
       }
       if(parameters){
       for(var param in parameters){
       paramNames.push(param);
       if(form.elements[param]){
       form.elements[param].value = parameters[param];
       } else {
       var input = document.createElement("input");
       input.type="hidden";
       input.name=param;
       input.value=parameters[param];
       form.appendChild(input);
       }
       }
       }
       form.submit();
       _clearJSFFormParameters(formName,target,paramNames);
      
       } else {
       alert("Form "+formName+" not found in document");
       }
       return false;
      };
      So : no test is made on form.onsubmit()...
      we should have somewhere something like :
      function submitForm(f) {
       if (typeof f.onsubmit == "function") {
       var result = f.onsubmit();
       if (typeof result == "undefined" || result) {
       f.submit();
       }
       }else{
       f.submit();
       }
       return false;
      }
      or like it's done in a4j-ajax :
      1679 A4J.AJAX.SubmitRequest = function( containerId, formId ,domEvt , options ) {
      1678 // First - run onsubmit event for client-side validation.
      1679 LOG.debug("NEW AJAX REQUEST !!! with form :"+formId );
      1680// var form = A4J.AJAX.locateForm(event);
      1681 var form = window.document.getElementById(formId);
      1682 if( (!form || form.nodeName.toUpperCase() != "FORM") && domEvt ) {
      1683 var srcElement = domEvt.target||domEvt.srcElement||null;
      1684 if(srcElement){
      1685 form = A4J.AJAX.locateForm(srcElement);
      1686 };
      1687 };
      1688 // TODO - test for null of form object
      1689 if(!options.submitByForm && form && form.onsubmit) {
      1690 LOG.debug("Form have onsubmit function, call it" );
      1691 if( form.onsubmit() == false ){
      1692 return false;
      1693 };
      1694 };
      ...
      can you explain it or correct it for next release...
      Or if it's normal, can you explain me how can i do what i want to do...