skip to Main Content

I’m trying to trigger a function in js when clicking on save button in edit product admin page. I followed the suggestions from here: https://magento.stackexchange.com/questions/119542/calling-js-function-when-product-save-button-is-clicked

And I modify in

app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit.php

$this->setChild('save_button',
            $this->getLayout()->createBlock('adminhtml/widget_button')
                ->setData(array(
                    'label'     => Mage::helper('catalog')->__('Save'),
                    'onclick'   => 'productForm.submit(); myFunction();',
                    'class' => 'save'
                ))
        );

But I don’t know in which template should I put the myFunction(). I tried in

app/design/adminhtml/default/default/template/catalog/product/edit.phtml 

and

app/design/adminhtml/default/admintheme/template/catalog/product/edit.phtml


function myFunction(){
    console.log('test');
}

but with no success. So my question is: where should I put the function in order to be activated when the save button is clicked?

2

Answers


  1. This got long as a comment, so I’ve added it as an answer:

    Conjecture:

    Your scoping might be off. Add it to a top-level page like: index.html, then you can assign the function as:

    window.myFunction = () => console.log('test')
    

    Since window is a global variable, you should have access to it from your click handler!

    Hypothesis 2

    You could actually be putting the function in files that do not import at/before the click handler is triggered. (this seems a bit less probable)

    Login or Signup to reply.
  2. You can put your code here appdesignadminhtmldefaultdefaulttemplateindexnotifications.phtml

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search