Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Add custom Javascript code to field or button

  1. #1
    carlo75 is offline Senior Member
    Join Date
    Mar 2009
    Posts
    86

    Default Add custom Javascript code to field or button

    Hi to all
    I've installed 5.5.2 CE and I can't find a right way to put a javascript code in editviewdefs.php.
    Ive tried to add this code to custom/modules/namemodule/metadata/editviewdefs.php to a field, or a button:

    PHP Code:
    'javascript' => 'onBlur="function(this)";'
    but nothing injection is added to the field, if I try to show source HTML, also after emptying template cache.

    Can anyone put me in the right direction?

    Thanks in advance.
    Regards.

  2. #2
    Lita21 is offline Junior Member
    Join Date
    Jun 2010
    Posts
    1

    Default Template Cache

    Quote Originally Posted by carlo75 View Post
    Hi to all


    PHP Code:
    'javascript' => 'onBlur="function(this)";'
    but nothing injection is added to the field, if I try to show source HTML, also after emptying template cache.

    Can anyone put me in the right direction?

    Thanks in advance.
    Regards.
    I've installed 5.5.2 CE and I can't find a right way to put a javascript code in editviewdefs.php.
    Ive tried to add this code to custom/modules/namemodule/metadata/editviewdefs.php to a field, or a button:
    Visit Atlantic City Hotels

  3. #3
    agcopley is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Santiago, Chile
    Posts
    204

    Default Re: Add custom Javascript code to field or button

    Hi there,
    The function call should be, for example

    PHP Code:
              0 => 
              array (
                
    'name' => 'state_c',
                
    'studio' => 'visible',
                
    'label' => 'LBL_STATE',
                
    'displayParams' => 
                array (
                  
    'javascript' => 'onchange="initData();"',
                ),
              ), 
    and the javascript included like:
    PHP Code:
    $viewdefs ['Opportunities'] = 
    array (
      
    'EditView' => 
      array (
        
    'templateMeta' => 
        array (
          
    'form' => 
          array (
            
    'hidden' => 
            array (
              
    'customCode' => '<input type="hidden" name="consortium_c" value="{$fields.consortium_c.value}">',
            ),
            
    'buttons' => 
            array (
              
    => 'SAVE',
              
    => 'CANCEL',
            ),
          ),
          
    'maxColumns' => '2',
          
    'includes' => 
          array (
            
    => 
            array (
              
    'file' => 'include/javascript/yashvi_js/stateregion1.js',
            ),
          ), 

    Rgds
    Andrew

  4. #4
    carlo75 is offline Senior Member
    Join Date
    Mar 2009
    Posts
    86

    Default Re: Add custom Javascript code to field or button

    Thanks Andrew
    for your response, I'll try also your solution!

  5. #5
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Add custom Javascript code to field or button

    Remember this works only for Dropdown fields.
    if you are trying to apply such event on a text field you need to specify the attribute

    PHP Code:
    'displayParams' => array(
     
    'field' => 'onBlur=somescript();'
    ), 

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  6. #6
    agcopley is offline Sugar Community Member
    Join Date
    Nov 2007
    Location
    Santiago, Chile
    Posts
    204

    Default Re: Add custom Javascript code to field or button

    Quote Originally Posted by andopes View Post
    Remember this works only for Dropdown fields.
    if you are trying to apply such event on a text field you need to specify the attribute

    PHP Code:
    'displayParams' => array(
     
    'field' => 'onBlur=somescript();'
    ), 
    Cheers
    Thanks André ! I was just too eager.

  7. #7
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: Add custom Javascript code to field or button

    Hi,

    This solution is nor working for Text Box. Can you provide more explanation over that..

    Please

    Regards,
    Pravin

  8. #8
    davidboris is offline Sugar Community Member
    Join Date
    May 2010
    Posts
    1,113

    Default Re: Add custom Javascript code to field or button

    Hello,

    Till now, Sugar is not supporting displayParams for text field.
    Thumbs up.

    Skype ID - david__boris

    SugarForge Projects:

    WYSIWYG now in studio!(Version 1.1 is out now!)

    Sugar Feeds on your personalized home pages like iGoogle, My Yahoo!, etc.

    Fab Tools! > Dashlet Not Followed Opportunities for past six Months

  9. #9
    kinshibuya's Avatar
    kinshibuya is offline A Sugar Hero
    Join Date
    Jul 2008
    Location
    brasil
    Posts
    521

    Default Re: Add custom Javascript code to field or button

    Hi,

    For my javcascript that works on editview with textcode is this one:

    editviewdefs.php

    PHP Code:
    $viewdefs [$module_name] = 
    array (
      
    'EditView' => 
      array (
        
    'templateMeta' => 
        array (
          
    'maxColumns' => '2',
          
    'widths' => 
          array (
            
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
            
    => 
            array (
              
    'label' => '10',
              
    'field' => '30',
            ),
          ),
          
    'includes' => 
          array (
            
    => 
            array (
              
    'file' => 'modules/FATUR_Emissao/name.js'//call for the js file
            
    ),
          ),
        ),
        
    'panels' => 
        array (
          
    'default' => 
          array (
            
    => 
            array (
              
    => 
              array (
                
    'name' => 'name',
                
    'label' => 'LBL_NAME',
                
    'customCode' => "<input type='text' class='right' value='' id='name'  onFocus='nomeemissao();'>",
              ), 

    and my javascript file is this one

    Code:
    function nomeemissao(){
    
     
      contrato = document.getElementById('contrato').value;
      
      name ='DT_FATUR_'+contrato;
      document.getElementById('name').value = name;
      
      
    }

    This code get the field 'contrato' and append something to it then it update the field 'name'.
    from this one you can see how the dynamic work for textfields.
    Priscila Kin Yamamoto Joranhezon
    Phone: +55 61 32010000
    priscila.joranhezon@nct.com.br
    NCT Informática Ltda

  10. #10
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Add custom Javascript code to field or button

    Another good approach avoiding customCode is something like that:

    PHP Code:
              array ( 
                
    'name' => 'name'
                
    'label' => 'LBL_NAME'
                
    'displayParams' => 
                array (
                  
    'field' => 
                  array (
                    
    'onFocus' => 'nomeemissao();',
                  ),
                ),
              ), 
    Regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 2011-07-06, 10:50 AM
  2. Problem with Javascript on Save Button custom code
    By swhitlow in forum Developer Help
    Replies: 7
    Last Post: 2011-02-16, 06:25 PM
  3. Custom Code Field in a Report
    By jkuehlthau in forum Developer Help
    Replies: 3
    Last Post: 2010-04-07, 06:03 PM
  4. custom function call from custom code field in metadata
    By josh.sweeney in forum Developer Help
    Replies: 9
    Last Post: 2010-02-09, 09:23 PM
  5. Custom code for a custom field in default module
    By kodikarthi in forum Developer Help
    Replies: 7
    Last Post: 2009-02-19, 04:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •