+ Start a Discussion
WahibIdrisWahibIdris 

Home page component - Summer 15

Hi,

I was using HTML component in home page component for advance search functionality in Narrow (Left) Column of Home Layout. My HTML component was 
<script language="JavaScript" type="text/javascript"> 
function setFocusOnLoad() {} 
function submitSearchForm(){ 
var searchField = document.getElementById('advsearchfield'); 
document.advsrch.action = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + encodeURIComponent(searchField.value); 
return true; 
} 

</script> 

<form name="advsrch" method="post" onsubmit="return submitSearchForm();"> 
<input class="searchTextBox" id="advsearchfield" maxlength="80" size="18" name="sbstr" />
<input class="btn" value=" Go! " type="submit" /> 
</form>


Now that component is not visible in Summer 15 org, so for the workaround I have created visualforce component and create VF page, below is my code of VF page
<apex:page > 

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" /> 
<apex:includeScript value="{!$Resource.advSearch}"/> 

</apex:page>

advSearch.js (Static Resource) is
 
$(document).ready(function () { 
function setFocusOnLoad() {} 
function submitSearchForm(){ 
var searchField = document.getElementById('advsearchfield'); 
document.advsrch.action = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + encodeURIComponent(searchField.value); return true; 
} 

$form = $("<form/>",{name:"advsrch"},{method:"post"},{onsubmit:"return submitSearchForm();"} ); 
$form.append('<input class="searchTextBox" id="advsearchfield" maxlength="80" size="18" name="sbstr" />'); 
$form.append('<input class="btn" value=" Go! " type="submit"/>'); 

$('body').append($form); });

After doing all the changes, I have found couple of issues 

1) Its not showing the blue container as it is now VF component. Requirement is to show the advance search text field and button in blue container just like other components.
2) Its not calling the function same way as it was before, now it refreshing the whole page   and not going link which I am providing. 

Not sure what am I missing or whats need to be done. Any help would be appreciated. Thanks much 
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi ,

Please refer this post.
http://bobbuzzard.blogspot.ae/2014/06/javascript-in-salesforce-home-page.html

Let us know if it helps you.
 
Avinash NelluriAvinash Nelluri
Replace 

document.advsrch.action = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + encodeURIComponent(searchField.value);

With

var url = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + encodeURIComponent(searchField.value);
window.open(url,'_top');

This should work. Let me know if you come across any issues.

Avinash.
JessBJessB
This is great, but I am having the problem that when I search, the results are loading within that VF sidebar component, not the whole webpage. How do we get the action to be the search results appearing in the wide area?
Avinash NelluriAvinash Nelluri
@JessB: Just copy paste the below code in visualforce page and create visualforce area component. This should work.

<apex:page>
<script language="JavaScript" type="text/javascript">
    function setFocusOnLoad() {}

    function submitSearchForm() {
        var searchField = document.getElementById('advsearchfield');
        var url = '/search/SearchResults?searchType=2&sen=0&setLast=1&str=' + encodeURIComponent(searchField.value);// see if you've to                                                                                                                                       change this depending on the search restrictions.
        window.open(url, '_top'); // This Makes sure the search results open in an entire tab instead of inside the component.
        return true;
    }
</script>

<form name="advsrch" method="post" onsubmit="return submitSearchForm();">
    <input class="searchTextBox" id="advsearchfield" maxlength="80" size="18" name="sbstr" />
    <input class="btn" value=" Go! " type="submit" />
</form>
</apex:page>