I have a Visualforce page that uses jQuery for various functions. One thing I'm trying to do is using the jQuery.isEmpty function on an apex:repeat value.
Relevant Visualforce code:
<apex:pageBlockSection id="existingOpps" columns="3" title="Existing opportunities" collapsible="false">
<apex:repeat id="oppRepeatValue" value="{!existingOpps}" var="o">
<apex:outputLabel id="OpportunityText" value="{!o.forOpportunityName__c}"></apex:outputLabel>
<apex:outputLabel value="{!o.forVisitReportName__c}"></apex:outputLabel>
<apex:outputLabel value="{!o.forVisitReportDate__c}"></apex:outputLabel>
</apex:repeat>
</apex:pageBlockSection>
The Visualforce code is translated into HTML code that looks like this:
<table class="detailList" border="0" cellpadding="0" cellspacing="0"><tr><th class="labelCol vfLabelColTextWrap first last " scope="row"><label for="j_id0:theForm:pb:existingParticipants:partRepeatValue:0:participantText">Type</label></th><td class="dataCol first last "><span id="j_id0:theForm:pb:existingParticipants:partRepeatValue:0:participantText" style="label">Contact</span></td><td class="dataCol first last " colSpan="2"><label id="j_id0:theForm:pb:existingParticipants:partRepeatValue:0:participantname" style="label"></table>
So, my question is, how can I use jQuery (or just plain JavaScript techniques) to check whether that generated table is empty or not? What I've tried so far is this JavaScript function.
function checkValidOnExit(){
var pso = document.getElementById("{!$Component.theForm.pb.existingParticipants.participantname}");
var oso = document.getElementById("{!$Component.theForm.pb.existingOpps}");
if(j$.isEmptyObject(pso) || j$.isEmptyObject(oso))
window.alert("error");
}
I.e by trying to check whether the HTML object/container is empty. If so, alert the user through the page being viewed (ApexPages.Message, etc.). What is the best way to handle this? Pure JavaScript function or use a controller method?