1

I have to call custom jquery function into Magento backend (sales > Order > View)

enter image description here

I have created custom js in adminhtml/web/js/order_status_validation.js

require(['jquery'], function(jQuery){
jQuery(function(){

    function do_validation_history() {
        alert('Coming');
        return false;
    }

  });
});

While we can click on submit button we are getting an error like

 ReferenceError: do_validation_history is not defined

I have called custom js into sales_order_view.xml

Can anyone know how we can resolve this error?

1
  • are you sure order_status_validation.js is coming on the page.? – Shashank Kumrawat Oct 5 '18 at 11:04
1

Below I am sharing the way I use for any jquery in magento 2. Let me know if you feel any difficulty to understand.

require(['jquery'], function(jQuery){

    var do_validation = {
        history: function (event){
            alert('Coming');
            return false;
        }
    }

    window.do_validation = do_validation;
});

Now you can use do_validation.history(event); from any where on the page.

You can also use below function outside of require js and call the function outside on the same page

function do_validation_history() {
        alert('Coming');
        return false;
    }
0
1

Its working fine with blow code

require([
'jquery',
 ], function(jQuery){

historyValidate = {
    validation: function(url) {
        console.log('this is test');
        return false; 
    }
}
jQuery(function ($) {
    console.log('this is test');
  });
 });

now adding historyValidate.validation(event); where my function call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.