I created a table using with Account lookup field along with other fields. I have assigned same style class name to all lookup as they're mandatory. VF code:
<apex:page>
<apex:pageblock>
<apex:pageblocktable value="{!conList}" var="c">
<apex:column><apex:outputText value="{!c.Name}" /></apex:column>
<apex:column><apex:inputField value="{!c.AccountId}" style="reqCheck"/></apex:column>
</apex:pageblocktable>
<apex:commandButton value="save" onclick="if(!Validation()){return false;}" />
<apex:pageblock>
</apex:page>
User will get a list of contacts who can change the Account but can't put null value in account before saving. On save buttons have executed a jquery validation as follows:
<script>
function Validation(){
var index;
$('.reqCheck').each(function(){
index = 0;
var r1=$.trim($(this).val());
if(!r1){
index = 1;
alert('Account is empty.Please fill it');
$(this).focus();
return false;
}
});
if(index == 0) return true;
else return false;
}
</script>
Problem: Here,in html(inspect element) style class 'reqCheck' is assigning for lookup icon too. And my javascript code is checking the lookup icon value which will be null and throwing the error even if the accountId is filled.