2

There is a widget loaded by data-mage-init that I need to run code after it has triggered the change event on the product options, why it does this I don't know, I commented out the line that triggers the change event but the module still works perfectly.

I need to alter some other things on the page when the drop downs are changed. The problem is the drop downs are changed on load because data-mage-init loads this widget which uses trigger() to call the change event on all the select drop downs. I need to define my change events after this runs, otherwise I will have code executing just on page load, instead of when a drop down is changed, which is bad.

I am looking for a simple hook to execute code after ALL mage-init scripts have been looped over and loaded.

1 Answer 1

1

I think this is not the perfect answer this is a hint.

@Wolfe -can you find a data-bind attribute, if can I can give you a hint. Knockout Js use render events eg. afterRender, beforeRender like

Then if you can add afterRender event and can call your custom function. eg.

    <span class="counter-number" data-bind="text: getQuantity(),afterRender:setSummeryQty"></span>

afterRender:setSummeryQty here call the setSummeryQty() js function,

5
  • Cool thank you I'll try this out and report back
    – user44406
    Commented Dec 23, 2017 at 9:12
  • @wolfe - I also wanted to duplicate value and set action after ko js load, so I have tried afterRender and put my custom js function, its works.
    – Lasantha
    Commented Dec 23, 2017 at 9:50
  • @wolfe - Have check it
    – Lasantha
    Commented Dec 27, 2017 at 18:34
  • yep it works thanks :D Now I just have to figure out how to run something enclosed in a require.js module from this method :)
    – user44406
    Commented Dec 28, 2017 at 7:57
  • @wolfe - Good , we have to learn ko js to continue the m2
    – Lasantha
    Commented Dec 28, 2017 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.