Calling Javascript function from a relate field in Editview

Hello developers!

I need to call a javascript function when a record is chosen in a relate field (in the editview).

i know how to do that with standard fields like dropdowns and others but the javascript function is not called on relate fields.

1. i added the include in custom/modules/aa_Subscriptions/metadata/editviewdefs.php

'includes' =>
   array (
      0 =>
      array (
         'file' => 'custom/modules/aa_Subscriptions/Subscription.js',
      ),
),

2. added the "onchange" event in the field:

0 => 

array (

   'name' => 'aos_products_aa_subscriptions_2_name',

   'displayParams' => 

      array (

         'field' => 

            array (

               'onChange' => 'doSomthing(this.value);',

            ),

      ),

),

3. added a javascript file  custom/modules/aa_Subscriptions/Subscription.js

function doSomthing(param)
{
   alert('write your code here');

}

any way for that to work?

i really really need to find a solution for this. any help will do...

Parents
  • Hi Asaf Army

    Try this and let me know for further help:

    1. Add the javascript in custom/modules/aa_Subscriptions/metadata/editviewdefs.php
    'templateMeta' =>
    // Add this code
    array (
    'javascript' => '
    <script src="./include/javascript/jquery.min.js" type="text/javascript"></script>
    <script src="./custom/modules/aa_Subscriptions/Subscription.js" type="text/javascript"></script>
    ',
    ),
    2. added the "onchange" event:
    0 =>
    array (
    'name' => 'aos_products_aa_subscriptions_2_name',
    'displayParams' =>
    array (
    'javascript' => 'onchange=doSomthing(this.value);',
    ),
    ),

    3. added a javascript file custom/modules/aa_Subscriptions/Subscription.js
    function doSomthing(param)
    {
    alert('write your code here');

    }

    Hope this Helps..!!

    Best Regards

    S Ramana Raju

  • Thank you, but it still doesn't call the javascript function (also made rebuild and cleaned the browser cache):

    <?php
    $module_name = 'aa_Subscriptions';
    $viewdefs [$module_name] =
    array (
    'EditView' =>
    array (
    'templateMeta' =>
    array (
    0 =>
    array (
    'javascript' => '
    <script src="./include/javascript/jquery.js" type="text/javascript"></script>
    <script src="./custom/modules/aa_Subscriptions/Subscriptions.js" type="text/javascript"></script>
    ',
    ),

    in the javascript file:

    $(document).ready(function(){
    function doSomthing(param)
    {
    alert('write your code here');
    }
    });

  • Hi Asaf Army

    I tried in my custom module for field with dropdown as data type and below code is working for me.
    Can you try in this way and let me know for further help.
    In custom/modules/aa_Subscriptions/metadata/editviewdefs.php added following code:

    'templateMeta' => 
        array (
          'form' =>
          array (
            'buttons' =>
            array (
              0 => 'SAVE',
              1 => 'CANCEL',         
            ),
          ),
          'includes' =>
          array (
            0 =>
            array (
              'file' => 'custom/modules/aa_Subscriptions/Subscription.js',
            ),
          ),
        ),
    'panels' =>
        array (
          'lbl_account_information' =>
          array (
                   0 =>
                   array (
                     0 =>
                     array (
                        'name' => 'aos_products_aa_subscriptions_2_name',
                        'displayParams' =>
                        array (
                          'javascript' => 'onchange=doSomthing(this.value);',
                        ),
                     ),
                   ),
              ),
         ),

    Here is Subscription.js code (custom/modules/aa_Subscriptions/Subscription.js):

    function doSomthing(cvalue)
    {    
         alert(cvalue," Hi Friends am triggered..");                                  
    }

    Its working for me.
    Let me know for further help.
    Hope this Helps..!!

    Best Regards
    S Ramana Raju

Reply
  • Hi Asaf Army

    I tried in my custom module for field with dropdown as data type and below code is working for me.
    Can you try in this way and let me know for further help.
    In custom/modules/aa_Subscriptions/metadata/editviewdefs.php added following code:

    'templateMeta' => 
        array (
          'form' =>
          array (
            'buttons' =>
            array (
              0 => 'SAVE',
              1 => 'CANCEL',         
            ),
          ),
          'includes' =>
          array (
            0 =>
            array (
              'file' => 'custom/modules/aa_Subscriptions/Subscription.js',
            ),
          ),
        ),
    'panels' =>
        array (
          'lbl_account_information' =>
          array (
                   0 =>
                   array (
                     0 =>
                     array (
                        'name' => 'aos_products_aa_subscriptions_2_name',
                        'displayParams' =>
                        array (
                          'javascript' => 'onchange=doSomthing(this.value);',
                        ),
                     ),
                   ),
              ),
         ),

    Here is Subscription.js code (custom/modules/aa_Subscriptions/Subscription.js):

    function doSomthing(cvalue)
    {    
         alert(cvalue," Hi Friends am triggered..");                                  
    }

    Its working for me.
    Let me know for further help.
    Hope this Helps..!!

    Best Regards
    S Ramana Raju

Children
No Data