JQuery hide buttons but after another event they are shown again

jquerymanaged-packagevisualforce

I have installed a managed package that has a VF Page and a static resource (JS). I cannot change neither the code of this static resource nor the VF, but i have the ability to create another static resource (JS) and write some code for customizations. The thing is: the Visualforce page is loaded and some buttons are shown by default. Then, my VF Page loads and through jQuery, i hide them. However, after clicking a "Finish" button, those buttons are shown again. I can't find a way to somehow permanently hide those buttons from DOM or at least trigger the "hide" code snippet to hide them. Is there a way to permanently hide those buttons? My code is:

//Logic to be triggered every time all rules are executed
CS.EventHandler.subscribe(CS.EventHandler.Event.RULES_FINISHED, function (payload) {
    //Hide the "Add" Buttons on Related Products
    jQuery('[data-cs-type="add"]').hide();
});

I also tried to add a CSS rule, but i didn't manage to find solution.

//Logic to be triggered every time all rules are executed
CS.EventHandler.subscribe(CS.EventHandler.Event.RULES_FINISHED, function (payload) {
    //Hide the "Add" Buttons on Related Products
    jQuery('[data-cs-type="add"]').hide();
    document.styleSheets[0].insertRule("[data-cs-type='add'] { display: none; }");
});

Best Answer

Could you create another css resource directly and load the rule as you were setting dynamically?

[data-cs-type='add'] { display: none; }

The issue is that the button rerender the page (if not reload), or a portion of it, so that all the content set dynamically is removed as the page is generated again.

You would need an oncomplete event after the action of the button, or maybe in your code if you can subscribe to another event that is triggered after finish and insert the css rule after it in the document, it can work.

Worst case, that I don't know if it will work, is just directly using the setInterval in the JS to hide the element, every X milliseconds, if the element is not yet hidden.

Related Topic