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

    Your code syntax is wrong Asaf.

    Correct it as:

    $module_name = 'aa_Subscriptions';
    $viewdefs [$module_name] =
    array (
      'EditView' =>
      array (
        'templateMeta' =>
         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>
                   ',
         ),
         'panels' =>
        array (
          'lbl_account_information' =>
          array (
                   0 =>
                   array (
                     0 =>
                     array (
                        'name' => 'aos_products_aa_subscriptions_2_name',
                        'displayParams' =>
                        array (
                          'javascript' => 'onchange=doSomthing(this.value);',
                        ),
                     ),
                   ),
              ),
         ),
         ),
         );

    Save & Do R&R.

    Let me know for further help.

    Best Regards

    S Ramana Raju

Reply
  • Hi Asaf Army

    Your code syntax is wrong Asaf.

    Correct it as:

    $module_name = 'aa_Subscriptions';
    $viewdefs [$module_name] =
    array (
      'EditView' =>
      array (
        'templateMeta' =>
         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>
                   ',
         ),
         'panels' =>
        array (
          'lbl_account_information' =>
          array (
                   0 =>
                   array (
                     0 =>
                     array (
                        'name' => 'aos_products_aa_subscriptions_2_name',
                        'displayParams' =>
                        array (
                          'javascript' => 'onchange=doSomthing(this.value);',
                        ),
                     ),
                   ),
              ),
         ),
         ),
         );

    Save & Do R&R.

    Let me know for further help.

    Best Regards

    S Ramana Raju

Children