I need some help understand how JavaScript and Visualforce interact.
I have a eventListener that works perfectly when the DOM is loaded:
window.addEventListener('DOMContentLoaded', function() {
if ('{!bvs.Status__c}' != 'Completed') {
document.getElementById("populatedChart").style.display = "none";
}
if ('{!bvs.Status__c}' == 'Completed') {
document.getElementById("oldPullreportbutton").style.display = "none";
}
if ('{!bvs.CompanyName__c}'.length > 0) {
document.getElementById("blankComp").style.fontWeight="bold";
}
});
I also have some code that tells the div to reRender after a button click:
<apex:commandLink action="{!pullReport}" onclick="showCreditPull()" oncomplete="stopSpinner()" value="Pull Report"/>
function showCreditPull() {
var panel = $('.spinBorder');
var spinner = panel.find(".business-loading-icon");
spinner.show();
}
function stopSpinner(){
var panel = $('.spinBorder');
var spinner = panel.find(".business-loading-icon");
spinner.hide();
rerenderData();//this is an actionFunction that reRenders the div
if ('{!bvs.Status__c}' != null){
document.getElementById("oldPullreportbutton").style.display = "none";
}
else{
$("#populatedChart").replaceWith( "<p>Error!</p>" );
}
}
My question is- why does is {!bvs.Status__c}
in stopSpinner()
not recognized? No matter what the status is, it runs through and hides the oldPullreportbutton
. It's acting like it doesn't recognize the binded {!bvs.Status__c}
. But it is able to be read with the eventListener.
UPDATE: Code from inspect:
if(true){
document.getElementById("oldPullreportbutton").style.display = "none";
$("#populatedChart").replaceWith( "<p>Error!</p>" );
console.log('got out 1');
}