How to show a popup ?
A popup dialog will be very useful in cases where an temporary information needs to be shown to the user for either user Input/Output.How to load a page in popup ?
There's no standard popup techniques in Visualforce. So, we need to create a custom Popup & load a visualforce page on that using window.open API method.
How to interact with popup & parent page ?
From the popup, its possible to interact with parent page in two ways,- By manipulating parent DOM directly.
- By triggering events to parent body component
Where is the Code ?
I have illustrated the custom popup through a parent page where we have a Text Field that will be populated when the user selects the account in the dialog box.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Opportunity"> | |
<apex:form> | |
<apex:outputLabel value="Account Name"/> | |
<apex:inputText value="{!Opportunity.Account.Name}" Id="AccNameId"/> | |
<!-- Custom Lookup for Account Record --> | |
<apex:outputLink value="javascript:void(0);" onclick="openDialog('{!$Component.AccNameId}');"> | |
find | |
</apex:outputLink> | |
</apex:form> | |
<script> | |
function openDialog(fieldId) { | |
window.open('{!URLFOR($Page.myDialogPage)}' + '?accTagId=' + fieldId, | |
'Popup', | |
'height=500,width=800,resizable=no,left=100,top=100'); | |
} | |
</script> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Account" recordSetVar="recs" sidebar="false" showHeader="false"> | |
<apex:form> | |
<apex:pageBlock title="Select a Account from the list"> | |
<apex:pageBlockSection> | |
<apex:pageBlockTable value="{!recs}" var="rec"> | |
<apex:column> | |
<apex:inputCheckbox onchange="onchecked(this, '{!rec.Name}')" /> | |
</apex:column> | |
<apex:column value="{!rec.Name}"/> | |
<apex:column value="{!rec.TickerSymbol}"/> | |
<apex:column value="{!rec.Website}"/> | |
<apex:column value="{!rec.AccountSource}"/> | |
<apex:column value="{!rec.Industry}"/> | |
</apex:pageBlockTable> | |
</apex:pageBlockSection> | |
</apex:pageBlock> | |
</apex:form> | |
<script> | |
function onchecked(elmt, accName) { | |
if (!elmt.checked || !window.parent || !accName) return; | |
var document = (window.opener && window.opener.document) || | |
(indow.parent.opener && window.parent.opener.document); | |
var accTag = document.getElementById('{!$CurrentPage.Parameters.accTagId}'); | |
accTag.value = accName; | |
window.close(); | |
} | |
</script> | |
</apex:page> |
No comments:
Post a Comment
Thanks for reading my blog !