You need to sign in to do that
Don't have an account?
justinhowell82
override openLookup inside apex component
I follwoed the instructions found here: http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/ which are pretty straight forward to try to override the standard lookup functionality. I implemented this within my apex component and it is never getting inside the function openLookup that I have defined within my component. Is there anything that would need ot be done differently when called from a component vs a VF page?
<pre>
<apex:component controller="MyCustomLookupController" allowDML="true">
<script type="text/javascript">
function openLookup(baseURL, width, modified, searchParam){
var originalbaseURL = baseURL;
var originalwidth = width;
var originalmodified = modified;
var originalsearchParam = searchParam;
var lookupType = baseURL.substr(baseURL.length-3, 3);
//var lookupType = baseURL.substr(baseURL.indexOf(‘lktp’)+5, 3);
if (modified == '1') baseURL = baseURL + searchParam;
var isCustomLookup = false;
// Following "001" is the lookup type for Account object so change this as per your standard or custom object
if(lookupType == "001"){
var urlArr = baseURL.split("&");
var txtId = '';
if(urlArr.length > 2) {
urlArr = urlArr[1].split('=');
txtId = urlArr[1];
}
// Following is the url of Custom Lookup page. You need to change that accordingly
baseURL = "/apex/CustomAccountLookup?txt=" + txtId;
// Following is the id of apex:form control "myForm". You need to change that accordingly
baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
if (modified == '1') {
baseURL = baseURL + "&lksearch=" + searchParam;
//baseURL = baseURL + searchParam
}
// Following is the ID of inputField that is the lookup to be customized as custom lookup
if(txtId.indexOf('Vendor') > -1 ){
isCustomLookup = true;
}
}
if(isCustomLookup == true){
openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}
else {
if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;
openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true); }
}
</script>
<apex:sectionHeader title="Demo" subtitle="Custom Lookup" />
<apex:form id="myForm" >
<!--<apex:outputLabel value="{!QID}" />-->
<apex:pageBlock id="AdjustQuoteLines">
<apex:inputField ID="Vendor" value="{!contact.AccountId}" />
</apex:PageBlock>
</apex:form>
</apex:component>
</pre>
All Answers
<apex:component id="QuoteLinesComponent" controller="QuoteLinewrapperClassController" allowDml="true" >
<script type="text/javascript">
function openLookup(baseURL, width, modified, searchParam){
var originalbaseURL = baseURL;
var originalwidth = width;
var originalmodified = modified;
var originalsearchParam = searchParam;
//var lookupType = baseURL.substr(baseURL.length-3, 3);
var lookupType = baseURL.substr(baseURL.indexOf(‘lktp’)+5, 3);
if (modified == '1') baseURL = baseURL + searchParam;
var isCustomLookup = false;
// Following "001" is the lookup type for Account object so change this as per your standard or custom object
if(lookupType == "001"){
var urlArr = baseURL.split("&");
var txtId = '';
if(urlArr.length > 2) {
urlArr = urlArr[1].split('=');
txtId = urlArr[1];
}
// Following is the url of Custom Lookup page. You need to change that accordingly
baseURL = "/apex/QuoteVendorLookup?txt=" + txtId;
// Following is the id of apex:form control "myForm". You need to change that accordingly
baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
if (modified == '1') {
baseURL = baseURL + "&lksearch=" + searchParam;
//baseURL = baseURL + searchParam
}
// Following is the ID of inputField that is the lookup to be customized as custom lookup
if(txtId.indexOf('Vendor') > -1 ){
isCustomLookup = true;
}
}
if(isCustomLookup == true){
openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}
else {
if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;
openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true); }
}
<apex:form id="myForm" >
<!--<apex:outputLabel value="{!QID}" />-->
<apex:pageBlock id="AdjustQuoteLines" >
<apex:inputField ID="Vendor" value="{!contact.AccountId}"/>
public class QuoteLinewrapperClassController {
public QuoteLinewrapperClassController(){
QuoteLinesList = null;
contact = new Contact();
}
public Contact contact {get;set;}
}
<pre>
//var lookupType = baseURL.substr(baseURL.length-3, 3);
var lookupType = baseURL.substr(baseURL.indexOf(‘lktp’)+5, 3);
</pre>
Thanks,
Justin
<span class="lookupInput">
<input id="j_id0:QuoteLinesComponent:QuoteLinesComponent:myForm:AdjustQuoteLines:Vendor" maxlength="255" name="j_id0:QuoteLinesComponent:QuoteLinesComponent:myForm:AdjustQuoteLines:Vendor" onchange="getElementByIdCS('j_id0:QuoteLinesComponent:QuoteLinesComponent:myForm:AdjustQuoteLines:Vendor_lkid').value='';getElementByIdCS('j_id0:QuoteLinesComponent:QuoteLinesComponent:myForm:AdjustQuoteLines:Vendor_mod').value='1';" size="20" type="text">
<script>new ForeignKeyInputElement("j_id0:QuoteLinesComponent:QuoteLinesComponent:myForm:AdjustQuoteLines:Vendor","/_ui/common/data/LookupValidationServlet",null,true,{"acent":"001"});</script>
<a href="javascript:%20openLookup%28%27%2F_ui%2Fcommon%2Fdata%2FLookupPage%3Flkfm%3Dj_id0%253AQuoteLinesComponent%253AQuoteLinesComponent%253AmyForm%26lknm%3Dj_id0%253AQuoteLinesComponent%253AQuoteLinesComponent%253AmyForm%253AAdjustQuoteLines%253AVendor%26lktp%3D%27%20%2B%20getElementByIdCS%28%27j_id0%3AQuoteLinesComponent%3AQuoteLinesComponent%3AmyForm%3AAdjustQuoteLines%3AVendor_lktp%27%29.value%2C670%2C%271%27%2C%27%26lksrch%3D%27%20%2B%20escapeUTF%28getElementByIdCS%28%27j_id0%3AQuoteLinesComponent%3AQuoteLinesComponent%3AmyForm%3AAdjustQuoteLines%3AVendor%27%29.value.substring%280%2C%2080%29%29%29" id="j_id0:QuoteLinesComponent:QuoteLinesComponent:myForm:AdjustQuoteLines:Vendor_lkwgt" onclick="setLastMousePosition(event)" title="Account Name/Sub-Agency Lookup (New Window)"><img src="/s.gif" alt="Account Name/Sub-Agency Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className = 'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="Account Name/Sub-Agency Lookup (New Window)"></a></span>
<pre>
<apex:page controller="CustomAccountLookupController"
title="Search"
showHeader="false"
sideBar="false"
tabStyle="Account"
id="pg">
<apex:form >
<apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
<apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">
<!-- SEARCH TAB -->
<apex:tab label="Search" name="tab1" id="tabOne">
<apex:actionRegion >
<apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
<apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/>
<apex:inputText id="txtSearch" value="{!searchString}" />
<span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span>
</apex:outputPanel>
<apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
<apex:pageBlock id="searchResults">
<apex:pageBlockTable value="{!results}" var="a" id="tblResults">
<apex:column >
<apex:facet name="header">
<apex:outputPanel >Name</apex:outputPanel>
</apex:facet>
<apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:actionRegion>
</apex:tab>
<!-- NEW ACCOUNT TAB -->
<apex:tab label="New Account" name="tab2" id="tabTwo">
<apex:pageBlock id="newAccount" title="New Account" >
<apex:pageBlockButtons >
<apex:commandButton action="{!saveAccount}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<apex:pageBlockSection columns="2">
<apex:inputField value="{!Account.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:tab>
</apex:tabPanel>
</apex:outputPanel>
</apex:form>
</apex:page>
</pre>
<pre>
<apex:page id="Page" tabstyle="Contact">
<c:CustomLookupComp />
</apex:page>
</pre>
<pre>
<apex:component controller="MyCustomLookupController" allowDML="true">
<script type="text/javascript">
function openLookup(baseURL, width, modified, searchParam){
var originalbaseURL = baseURL;
var originalwidth = width;
var originalmodified = modified;
var originalsearchParam = searchParam;
var lookupType = baseURL.substr(baseURL.length-3, 3);
//var lookupType = baseURL.substr(baseURL.indexOf(‘lktp’)+5, 3);
if (modified == '1') baseURL = baseURL + searchParam;
var isCustomLookup = false;
// Following "001" is the lookup type for Account object so change this as per your standard or custom object
if(lookupType == "001"){
var urlArr = baseURL.split("&");
var txtId = '';
if(urlArr.length > 2) {
urlArr = urlArr[1].split('=');
txtId = urlArr[1];
}
// Following is the url of Custom Lookup page. You need to change that accordingly
baseURL = "/apex/CustomAccountLookup?txt=" + txtId;
// Following is the id of apex:form control "myForm". You need to change that accordingly
baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
if (modified == '1') {
baseURL = baseURL + "&lksearch=" + searchParam;
//baseURL = baseURL + searchParam
}
// Following is the ID of inputField that is the lookup to be customized as custom lookup
if(txtId.indexOf('Vendor') > -1 ){
isCustomLookup = true;
}
}
if(isCustomLookup == true){
openPopup(baseURL, "lookup", 350, 480, "width="+width+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true);
}
else {
if (modified == '1') originalbaseURL = originalbaseURL + originalsearchParam;
openPopup(originalbaseURL, "lookup", 350, 480, "width="+originalwidth+",height=480,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no", true); }
}
</script>
<apex:sectionHeader title="Demo" subtitle="Custom Lookup" />
<apex:form id="myForm" >
<!--<apex:outputLabel value="{!QID}" />-->
<apex:pageBlock id="AdjustQuoteLines">
<apex:inputField ID="Vendor" value="{!contact.AccountId}" />
</apex:PageBlock>
</apex:form>
</apex:component>
</pre>
I have implemented openLookup(baseURL, width, modified, searchParam) to override the lookup popup window in my VisualforcePage, its working fine, but it will not working in Detail view page (I am using <apex:detail> in my VF page), as there will not available ID for the lookup field. Can you suggest me how to achive this in Detail view page also.
Thanks,
Haripriya
This is my VF page, that inserting new object: This is controller for this page: And this is lookup page:
When i open main page ( inserting new object ) and starting lookup page the value from lookup page passing to may main window. But if i starting lookup page again ( for example, i chosed false organization and would like to chose it again) my lookup page don't close and don't passing value to parent window and i have error" Uncaught TypeError: Cannot read property 'nextSibling' of null
at ForeignKeyInputElement.applyValidationChanges (main.js:706)
at Function.ForeignKeyInputElement.dispatchLookupChange (main.js:697)
at doLookupPick (main.js:39)
at lookupPick2 (main.js:45)
at <anonymous>:1:19"
How can i solve this issue?