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');
    }
    });

  • No. Still doesn't show the javascript alert when i choose a product in aos_products_aa_subscriptions_2_name field.

    Did all that you wrote.

    I really appreciate your effort. thank you very much!

  • Hi Asaf

    For me both code which i suggested is working.

    Can you share your code and what data type is your field ( i.e aos_products_aa_subscriptions_2_name ).

    If it is dropdown then when you change option of your dropdown do we getting an error or what.

    Can you check and let me know. So that i can help you further.

    Best Regards

    S Ramana Raju

Reply Children
No Data