Hi
Recently google has added autocomplete to there settings i have noticed.
Once i've checked the checkbox they said that i have to regenerate the code
But where can i add that into the module?
this is the generated code:
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'nl'});
google.setOnLoadCallback(function() {
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
customSearchControl.draw('cse', options);
}, true);
</script>
Comments
Comment #1
bryancasler commentedsubscribe
Comment #2
marco.1984 commentedHi naievepanda,
I have the same issue with Google CSE.
I created a new CSE from scratch with a new ID that I pass to the module, but it still doesnt work.
Anyone for more help please?
Comment #3
michiellucas commentedsubscribe
Comment #4
robinmcgsubscribe
Comment #5
healycn commentedSubscribing
Comment #6
udvranto commentedSubscribing
Comment #7
v8powerage commentedI think js should go to google_cse.js but that's not enough, some rewrite of the google_cse.module is needed.
Comment #8
Bahlool commentedsubscribe
Comment #9
jlea9378 commentedAny update on this? How do we get autocomplete to work?
Comment #10
sirish.ayyagari commentedany update on this
Comment #11
jlea9378 commentedany update on this???
Comment #12
dilipvertical commentedany updates still ???????
Comment #13
kevinchampion commentedHere's a patch to add autocomplete to the search form fields in search-form and search-form-block.
Comment #14
jlea9378 commentedI installed the patch and cleared my site cache, but I don't see the auto-completion working. Is there something else that needs to be done to enable it or get it working...?
Comment #15
kevinchampion commentedMake sure that in your actual Google Custom Search Engine settings that you've enabled autocomplete. Look under "Search Features" in the side menu, and then under the "Autocomplete" tab. If it wasn't set and you set it, you may run into another problem that the Autocomplete results are indexed separately, so it can take 5+ hours for Google to index the Autocomplete before you'll start seeing results.
There is also a potential problem with the way that the jsapi script in included in this patch, namely that there are environmental conditions that can get in the way of Drupal's ability to retrieve the external javascript file. I'm not totally versed on what all those might be, but I think the php setting allow_furl_open needs to be turned on (this would be in your php.ini, or wherever else you set your php settings).
If autocomplete is turned on and your CSE instance is working fine otherwise, I'd then check your browser's console to see if there are any javascript errors. If so, and if they're related to this patch, then the most likely problem is the jsapi script inclusion mentioned above. If that's the problem, then you can try downloading the jsapi script from Google and including it in the module locally.
Comment #16
jlea9378 commentedYes, it's enabled on my Search Features and I am successfully able to test it there in the preview of my CSE.
I checked the PHP settings and allow_url_fopen is enabled. I can also see in the browser console that the JS file is being successfully retrieved. However no autocomplete appears when typing in my search box on the web page, whereas typing the exact same thing in the preview of my CSE does cause the autocomplete to appear.
More ideas? My site is www.clatsopcc.edu in case you want to see it.
Comment #17
kevinchampion commentedI see 2 problems:
To resolve #1, since Google serves its jsapi over http or https, before including the script it'd need to check the current page's protocol and attempt to retrieve https instead of http. I'm not sure what the best-practice way of doing this is. A quicker fix in your case might be to just manually change the http to https.
Alternatively, you can download the script and include it in the module so that it's loaded locally, which won't have issue with http vs. https. Ideally it would be made into a library so it can be used easily across the site.
Comment #18
jlea9378 commentedKevinchampion, thanks for looking at my site. I didn't even realize it was working on the actual "Search" page.
I added code to hook_form_search_form_alter() to attach the JS to google-cse-results-searchbox-form, which is the ID of the form in the upper-right corner of my page. Now both forms on the search page have functioning autocompletes.
However, hook_form_search_form_alter() isn't getting executed on every other page of my site, so the autocomplete doesn't work on the rest of the site. I tried adding a new hook_form_FORM_ID_alter() for the google-cse-results-searchbox-form named "google_cse_form_google_cse_results_searchbox_form_alter()" but that doesn't seem to work. Any idea why? According to the Drupal API I am pretty sure I named the function correctly.
I'm stumped for now. Thanks for any help you can offer!
Comment #19
kevinchampion commentedYou must not have the correct form id. To figure it out, do an ordinary hook_form_alter and inspect the $form_id variable that's passed in to figure out what the form id is of that search form. You can leave your code inside a conditional statement that checks for the right form id, or move it to a hook_form_FORM_ID_alter statement.
Another note on http/https protocol complications. One common practice is to just leave off the protocol and do something like this:
//www.google.ca/jsapi
If I get a chance, I'll test this and re-roll another patch.
Comment #20
jlea9378 commentedOk I had the the form_id right and the method name right but apparently I was too impatient. It took several refreshes and cache clears before my dsm("TEST") message started appearing.
Ok, now my test message appears, so the function is entered, but the if statement is not entered because there is no 'module' id in the $form array. I looked at the dprint_r() of the $form variable and confirmed this to be the case.
This form (block) is the "Google GSE" block that was installed by the module, by the way.
Thanks for your help so far!
Comment #21
kevinchampion commentedThanks for pointing out the block form, I wasn't using it so I had overlooked it. Here's another patch to try.
Comment #22
jlea9378 commentedPatch on comment #21 works!
Comment #23
jat32 commentedThanks, Kevinchampion! Patch on comment #21 worked for me as well.
Comment #24
malcomio commentedPatch doesn't apply cleanly against 7.x-2.x
Comment #25
afinnarn commentedI tried re-rolling this patch into 7.x-2.x and it didn't work. Adding to considerations for D8 version.