I am quite new to Visualforce and Apex. I am trying to set focus on the apex inputText field, placed inside an ouputpanel, which will be popped up based on an action function. I tried setting focus using javascript function but none works. Can anyone please help me on this?
Visualforce code:
<apex:outputlabel onclick="fnUpdateName('{!ID}','{!Name}');" style="font-weight:normal !important;" > Edit name </apex:outputlabel>
<apex:actionfunction name="actUpdateName" action="{!ShowPopup}" reRender="UpdateName">
<apex:param name="Id" value="" assignTo="{!Id}"/>
<apex:param name="Name" value="" assignTo="{!Name}"/>
</apex:actionfunction>
output panel:
<apex:outputPanel id="UpdateName">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!update}"/>
<apex:outputPanel styleClass="customPopup" layout="block" rendered="{!update}">
<apex:pageBlock id="updatePageBlock">
<div class="panel panel-default">
<div class="panel-heading">
<h4><b Style="color:#555">Edit Name</b></h4>
</div>
<div class="panel-body">
<table class="tblPopUp">
<tr>
<td><font style="color:#337ab7">Name: </font></td>
<td> <apex:inputText id="newName" value="{!Name}" styleClass="inputField" onfocus="this.value = this.value;" /></td> <br/>
</tr>
</table>
<br/><br/>
<apex:commandButton value="Update" action="{!UpdateName}" Render="tblBlock"/>
<apex:commandButton value="Cancel" action="{!ClosePopup}" />
</div>
</div>
</apex:pageBlock>
</apex:outputPanel>
</apex:outputPanel>
JS function:
function fnUpdateName(ID, Name)
{
document.getElementById('{!$Component.frmid.DetBlock.tblBlock.popUpBlock.updatePageBlock.newName}').focus();
actUpdateName(ID, Name);
}
Also,I am getting the below Javascript error, whenever I use setFocus based on component ID, and class name.
Uncaught TypeError: Cannot read property 'focus' of null
Rendered DOM Id:
j_id0:frmid:DetBlock:tblBlock:popUpBlock:updatePageBlock:newName
Also please note, the above output label is located inside dynamically binded list tag.
Any help is really appreciated..!!