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!

Reply Children
  • 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

  • Thank you Ramana,

    just read my post , the first one:

    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.

    .....

    ....

    ...

    This is code:

    <?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>
    ',
    ),
    'maxColumns' => '2',
    'widths' =>
    array (
    0 =>
    array (
    'label' => '10',
    'field' => '30',
    ),
    1 =>
    array (
    'label' => '10',
    'field' => '30',
    ),
    ),
    'includes' =>
    array (
    0 =>
    array (
    'file' => 'custom/modules/aa_Subscriptions/Subscriptions.js',
    ),
    ),
    'useTabs' => false,
    'tabDefs' =>
    array (
    'DEFAULT' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL1' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL2' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL3' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL4' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    ),
    'syncDetailEditViews' => false,
    ),
    'panels' =>
    array (
    'default' =>
    array (
    0 =>
    array (
    0 => 'name',
    1 =>
    array (
    'name' => 'contacts_aa_subscriptions_1_name',
    ),
    ),
    1 =>
    array (
    0 =>
    array (
    'name' => 'register_status_c',
    'studio' => 'visible',
    'label' => 'LBL_REGISTER_STATUS',
    ),
    1 =>
    array (
    'name' => 'accounts_aa_subscriptions_1_name',
    ),
    ),
    2 =>
    array (
    0 =>
    array (
    'name' => 'register_date_c',
    'label' => 'LBL_REGISTER_DATE',
    ),
    1 =>
    array (
    'name' => 'leads_aa_subscriptions_1_name',
    ),
    ),
    3 =>
    array (
    0 =>
    array (
    'name' => 'details_confirmed_c',
    'studio' => 'visible',
    'label' => 'LBL_DETAILS_CONFIRMED',
    ),
    1 =>
    array (
    'name' => 'aa_classes_aa_subscriptions_1_name',
    ),
    ),
    4 =>
    array (
    0 =>
    array (
    'name' => 'trace_18_c',
    'studio' => 'visible',
    'label' => 'LBL_TRACE_18',
    ),
    1 => '',
    ),
    5 =>
    array (
    0 =>
    array (
    'name' => 'commnets_c',
    'studio' => 'visible',
    'label' => 'LBL_COMMNETS',
    ),
    1 => 'description',
    ),
    ),
    'lbl_editview_panel1' =>
    array (
    0 =>
    array (
    0 =>
    array (
    'name' => 'aos_products_aa_subscriptions_1_name',
    'displayParams' =>
    array (
    'field_to_name_array' =>
    array (
    'id' => 'aos_products_aa_subscriptions_1aos_products_ida',
    'name' => 'aos_products_aa_subscriptions_1_name',
    'product_price_c' => 'class_curse_price_c',
    ),
    'additionalFields' =>
    array (
    'product_price_c' => 'class_curse_price_c',
    ),
    ),
    ),
    1 =>
    array (
    'name' => 'class_curse_price_c',
    'label' => 'LBL_CLASS_CURSE_PRICE',
    ),
    ),
    1 =>
    array (
    0 =>
    array (
    'name' => 'subs_cost_add_c',
    'studio' => 'visible',
    'label' => 'LBL_SUBS_COST_ADD',
    ),
    1 =>
    array (
    'name' => 'subs_add_cost_c',
    'label' => 'LBL_SUBS_ADD_COST',
    ),
    ),
    2 =>
    array (
    0 =>
    array (
    'name' => 'aos_products_aa_subscriptions_2_name',

    ),
    1 =>
    array (
    'name' => 'discount_sum_c',
    'label' => 'LBL_DISCOUNT_SUM',
    ),
    ),
    3 =>
    array (
    0 =>
    array (
    'name' => 'sale_code_c',
    'label' => 'LBL_SALE_CODE',
    ),
    1 =>
    array (
    'name' => 'sale_code_sum_c',
    'label' => 'LBL_SALE_CODE_SUM',
    ),
    ),
    4 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'manager_discount_c',
    'label' => 'LBL_MANAGER_DISCOUNT',
    ),
    ),
    5 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'total_before_interest_c',
    'label' => 'LBL_TOTAL_BEFORE_INTEREST',
    ),
    ),
    6 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'payment_interest_sum_c',
    'label' => 'LBL_PAYMENT_INTEREST_SUM',
    ),
    ),
    7 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'credit_sum_c',
    'label' => 'LBL_CREDIT_SUM',
    ),
    ),
    8 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'final_sum_c',
    'label' => 'LBL_FINAL_SUM',
    ),
    ),
    9 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'paid_sum_c',
    'label' => 'LBL_PAID_SUM',
    ),
    ),
    10 =>
    array (
    0 => '',
    1 =>
    array (
    'name' => 'not_paid_c',
    'label' => 'LBL_NOT_PAID',
    ),
    ),
    ),
    'lbl_editview_panel2' =>
    array (
    0 =>
    array (
    0 =>
    array (
    'name' => 'name_mafne_c',
    'label' => 'LBL_NAME_MAFNE',
    ),
    1 =>
    array (
    'name' => 'cigarette_type_c',
    'studio' => 'visible',
    'label' => 'LBL_CIGARETTE_TYPE',
    ),
    ),
    1 =>
    array (
    0 =>
    array (
    'name' => 'num_mafne_c',
    'label' => 'LBL_NUM_MAFNE',
    ),
    1 =>
    array (
    'name' => 'credit_pass_to_c',
    'studio' => 'visible',
    'label' => 'LBL_CREDIT_PASS_TO',
    ),
    ),
    ),
    'lbl_editview_panel3' =>
    array (
    0 =>
    array (
    0 =>
    array (
    'name' => 'cred_request_date_c',
    'label' => 'LBL_CRED_REQUEST_DATE',
    ),
    1 =>
    array (
    'name' => 'cred_isok_c',
    'label' => 'LBL_CRED_ISOK',
    ),
    ),
    1 =>
    array (
    0 =>
    array (
    'name' => 'users_aa_subscriptions_1_name',
    'label' => 'LBL_USERS_AA_SUBSCRIPTIONS_1_FROM_USERS_TITLE',
    ),
    1 =>
    array (
    'name' => 'users_aa_subscriptions_2_name',
    'label' => 'LBL_USERS_AA_SUBSCRIPTIONS_2_FROM_USERS_TITLE',
    ),
    ),
    2 =>
    array (
    0 =>
    array (
    'name' => 'cred_start_handle_date_c',
    'label' => 'LBL_CRED_START_HANDLE_DATE',
    ),
    1 =>
    array (
    'name' => 'credit_return_c',
    'studio' => 'visible',
    'label' => 'LBL_CREDIT_RETURN',
    ),
    ),
    3 =>
    array (
    0 =>
    array (
    'name' => 'cred_result_c',
    'studio' => 'visible',
    'label' => 'LBL_CRED_RESULT',
    ),
    1 =>
    array (
    'name' => 'cred_receive_form_date_c',
    'label' => 'LBL_CRED_RECEIVE_FORM_DATE',
    ),
    ),
    4 =>
    array (
    0 =>
    array (
    'name' => 'manager_confirm_c',
    'studio' => 'visible',
    'label' => 'LBL_MANAGER_CONFIRM',
    ),
    1 =>
    array (
    'name' => 'cred_receive_credit_date_c',
    'label' => 'LBL_CRED_RECEIVE_CREDIT_DATE',
    ),
    ),
    5 =>
    array (
    0 =>
    array (
    'name' => 'demand_manager_approve_c',
    'label' => 'LBL_DEMAND_MANAGER_APPROVE',
    ),
    1 =>
    array (
    'name' => 'approved_by_manager_c',
    'label' => 'LBL_APPROVED_BY_MANAGER',
    ),
    ),
    6 =>
    array (
    0 =>
    array (
    'name' => 'cred_invoice_date_c',
    'label' => 'LBL_CRED_INVOICE_DATE',
    ),
    1 =>
    array (
    'name' => 'cred_cancel_reason_c',
    'studio' => 'visible',
    'label' => 'LBL_CRED_CANCEL_REASON',
    ),
    ),
    7 =>
    array (
    0 =>
    array (
    'name' => 'cred_damage_date_c',
    'label' => 'LBL_CRED_DAMAGE_DATE',
    ),
    1 =>
    array (
    'name' => 'general_payment_status_c',
    'studio' => 'visible',
    'label' => 'LBL_GENERAL_PAYMENT_STATUS',
    ),
    ),
    ),
    'lbl_editview_panel4' =>
    array (
    0 =>
    array (
    0 => 'assigned_user_name',
    ),
    ),
    ),
    ),
    );
    ?>

  • Hello,

    Try this in view.edit.php 

    <script language = "javascript">
    YAHOO.util.Event.onDOMReady(function(){

        YAHOO.util.Event.addListener('aos_products_aa_subscriptions_2_name', 'change', function(){ alert('write your code here');

        });

    });

    </script>

  • Hi Asaf,

    Remove this below js in editviewdef.php file

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

    onchange relate field Hash Softech solutions try it.

  • Thank you guys, but it still doesn't work:

    Where do i put the above javascript in the edit.view.php?

    did you mean like this?

    <?php
    $module_name = 'aa_Subscriptions';
    $viewdefs [$module_name] =
    array (
    'EditView' =>
    array (
    'templateMeta' =>
    array (
    0 =>
    array (
    'javascript' => '
    <script language = "javascript"> YAHOO.util.Event.onDOMReady(function(){ YAHOO.util.Event.addListener("aos_products_aa_subscriptions_2_name", "change", function(){ alert("write your code here");});});</script>
    ',
    ),
    'maxColumns' => '2',
    'widths' =>
    array (
    0 =>
    array (
    'label' => '10',
    'field' => '30',
    ),
    1 =>
    array (
    'label' => '10',
    'field' => '30',
    ),
    ),
    // 'includes' =>
    // array (
    //
    // 0 =>
    // array (
    // 'file' => 'custom/modules/aa_Subscriptions/Subscriptions.js',
    // ),
    // ),
    'useTabs' => false,
    'tabDefs' =>
    array (
    'DEFAULT' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL1' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL2' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL3' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    'LBL_EDITVIEW_PANEL4' =>
    array (
    'newTab' => false,
    'panelDefault' => 'expanded',
    ),
    ),
    'syncDetailEditViews' => false,
    ),
    'panels' =>
    array (
    'default' =>
    array (
    0 =>
    array (
    0 => 'name',
    1 =>
    array (
    'name' => 'contacts_aa_subscriptions_1_name',
    ),
    ),
    1 =>
    array (
    0 =>
    array (
    'name' => 'register_status_c',
    'studio' => 'visible',
    'label' => 'LBL_REGISTER_STATUS',
    ),
    1 =>
    array (
    'name' => 'accounts_aa_subscriptions_1_name',
    ),
    ),
    2 =>
    array (
    0 =>
    array (
    'name' => 'register_date_c',
    'label' => 'LBL_REGISTER_DATE',
    ),
    1 =>
    array (
    'name' => 'leads_aa_subscriptions_1_name',
    ),
    ),
    3 =>
    array (
    0 =>
    array (
    'name' => 'details_confirmed_c',
    'studio' => 'visible',
    'label' => 'LBL_DETAILS_CONFIRMED',
    ),
    1 =>
    array (
    'name' => 'aa_classes_aa_subscriptions_1_name',
    ),
    ),
    4 =>
    array (
    0 =>
    array (
    'name' => 'trace_18_c',
    'studio' => 'visible',
    'label' => 'LBL_TRACE_18',
    ),
    1 => '',
    ),
    5 =>
    array (
    0 =>
    array (
    'name' => 'commnets_c',
    'studio' => 'visible',
    'label' => 'LBL_COMMNETS',
    ),
    1 => 'description',
    ),
    ),
    'lbl_editview_panel1' =>
    array (
    0 =>
    array (
    0 =>
    array (
    'name' => 'aos_products_aa_subscriptions_1_name',
    'displayParams' =>
    array (
    'field_to_name_array' =>
    array (
    'id' => 'aos_products_aa_subscriptions_1aos_products_ida',
    'name' => 'aos_products_aa_subscriptions_1_name',
    'product_price_c' => 'class_curse_price_c',
    ),
    'additionalFields' =>
    array (
    'product_price_c' => 'class_curse_price_c',
    ),
    ),
    ),
    1 =>
    array (
    'name' => 'class_curse_price_c',
    'label' => 'LBL_CLASS_CURSE_PRICE',
    ),
    ),
    1 =>
    array (
    0 =>
    array (
    'name' => 'subs_cost_add_c',
    'studio' => 'visible',
    'label' => 'LBL_SUBS_COST_ADD',
    ),
    1 =>
    array (
    'name' => 'subs_add_cost_c',
    'label' => 'LBL_SUBS_ADD_COST',
    ),
    ),
    2 =>
    array (
    0 =>
    array (
    'name' => 'aos_products_aa_subscriptions_2_name',
    ),
    ),
    1 =>
    array (
    'name' => 'discount_sum_c',
    'label' => 'LBL_DISCOUNT_SUM',
    ),
    ),

  • Hi,

    You need to change popup window function change

    open_popup( "Campaigns",  600,  400,  "",  true,  false,  {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"module_id","name":"module_name"}},  "single",  true );

    Change custom function set_return_custom

    set_return function found in include/javascript/popup_parent_helper.js

  • Hi Asaf Army

    Sorry for miss understanding your question.

    Here is the working code:

    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',
            ),
          ),
        ),

    Now in your custom/modules/aa_Subcriptions/Subscription.js file add code as:

    YAHOO.util.Event.onDOMReady(function(){
        YAHOO.util.Event.addListener('aos_products_aa_subscriptions_2_name', 'change', function(){
        alert("You have selected: "+this.value);
        // Add your code here
        });
    });

    if you want to get selected related id then check down that field you will be having an hidden input field with 

    xxxxxxxxxxxxxx_ida as id and name. Copy that id and do as:

    YAHOO.util.Event.onDOMReady(function(){
        YAHOO.util.Event.addListener('aos_products_aa_subscriptions_2_name', 'change', function(){
        var id = $("#xxxxxxxxxx_ida").val();
        alert("You have selected: "+this.value+" with ID: "+id);
        // Add your code here           
        });
    });

    Hope this Helps..!!

    Best Regards

    S Ramana Raju