Template function ...

Hi ,

I’m formatting in tabbar main menu with form templates items . I’m doing this from database table , process is automated . Source :

         var formData = [];
         formData.push( { type: "settings", position: "label-left", inputWidth : 200 } );
         for ( s = 0; s < stp.length; s ++ )
         {
            formData.push( { type: "newcolumn", offset:50 } );
            for ( g = 0; g < grp.length; g ++ )
            {
               for ( u = 0; u < $pagr_men.length; u ++ )
               {
                  if ( $pagr_men[ u ][ 7 ] == stp[ s ] && $pagr_men[ u ][ 0 ] == grp[ g ] )
                  {
                     var img = $pagr_men[ u ][ 3 ];
                     var idt = $pagr_men[ u ][ 2 ];
                     var lab = $pagr_men[ u ][ 1 ];
                        if ( $.trim( img ).length > 0 )
                           formData.push( { type: "label", label: "<img src='images/" + img + "' />"} );
                        if ( $.trim( idt ).length > 0 )
                           formData.push( { type: "template", name: idt, value: lab, position: "label-left", format: "menuLink" } );
                  }
               }
            }
         }            
         
         var myMenuForm = mainTab.cells( "pagr_Men" ).attachForm( formData );
  ...

      function menuLink( name, value ) 
      {
         mineGlobal = name;
         return "<a href='javascript:void(0);' onclick='spausk();'>" + value + "</a>"; // with global
         //return "<a href='javascript:void(0);' onclick='spausk(" + name + ");'>" + value + "</a>";
      }      

      function spausk( menuId ) 
       {
           ...
       } 

or

       function spausk()
       {
          menuId = mineGlobal;
          ...
       }

The problem is that if to use uncommented line in menuLink() function ,
return “” + value + “”;
it return error that : Uncaught ReferenceError: uzs1 is not defined . Here uzs1 is template name . If to use return “” + value + “”; and global var , then I’m getting the last “name” . How to let to work templates as html hrefs ? Maybe mine function spausk() can recognize which template in form was pressed ? I didn’t found event or method for templates in form documentation .

With best regards and thanks in advance !

Problem solved … :slight_smile:

It needs format onClick event with ’ ’ . Sample :

 function menuLink( name, value ) 
      {
         var onCl = "spausk('" + name + "');";
         return '<a href="javascript:void(0);" onClick="' + onCl + '">' + value + '</a>';
      }      

Now all links a working as axpected … :wink: