contextual search how can I configure this button?

andy_dufresne
Tera Expert

Hello,

I have a contextual search, when a user searches it gives a list of "record producers".   The user wants to simple click on the link and it should take him to the required 'record producer'.

So I want to get rid of this button "Take Me To Form" [which does the right job, but want the url link before it to do the job]

find_real_file.png

I have searched everywhere in the contextual search and record producers, but cannot locate this "Take Me To Form" button.

1 ACCEPTED SOLUTION

Hi Andy.



You can get rid of the button with a catalog client script. Please be aware though, when you upgrade, there may be changes to Contextual Search could break your script. You'll be able to see if we've changed anything in contextual search in the release notes though.



This is the script:


function onLoad() {


      document.observe("cxs:target_update", function() {


              $$("#cxs_results_container button.request_catalog_button_with_icon").each(function(elem, index) {


                      elem.hide();


              });


      });


}



The event cxs:target_update is fired each time a search is completed.



This is what my catalog client script looks like:


find_real_file.png



This will only work on your record producer. If you wanted to do hide the Order button when displaying contextual search results on a form you would need to create an onLoad client script there too. The however should be the same.



Let me know if this works for you.



Thanks,



Cameron


View solution in original post

16 REPLIES 16

Hi Andy,



No problem .



This should do exactly what you want. Take the action that is performed when clicking the Order button and make the original link do that instead. I've added comments inline:


$$("#cxs_results_container a.service_catalog").each(function(elem, index) {


      var orderButtons = elem.adjacent(".request_catalog_button_with_icon");


      if (orderButtons.length == 0)


              return;



      var orderButton = orderButtons[0];


      orderButton.hide();



      elem.on("click", function(){


              event.stop(); // Stop the event from bubbling and from performing its default action


              window.location = orderButton.readAttribute("data-url"); // Change the windows location to the hidden button's URL


      });


});



That should do it. Let me know if you have any issues.



Thanks,



Cameron


That was brilliant -THANK YOU!



I put the brackets to complete your code, it all works as expected.   Have a great day!



--------------------------------------------------------------------------------------------


function onLoad() {


      document.observe("cxs:target_update", function() {


  $$("#cxs_results_container a.service_catalog").each(function(elem, index) {


      var orderButtons = elem.adjacent(".request_catalog_button_with_icon");


      if (orderButtons.length == 0)


              return;



      var orderButton = orderButtons[0];


      orderButton.hide();



      elem.on("click", function(){


              event.stop(); // Stop the event from bubbling and from performing its default action


              window.location = orderButton.readAttribute("data-url"); // Change the windows location to the hidden button's URL


      });


});


  });


  }


   


--------------------------------------------------------------------------------------------


andy_dufresne
Tera Expert

Hi Cameron,



While this works fine on a Chrome, the url takes me to the pop-up in the firefox [its probably ignoring that the url needs to direct to the target page instead of the pop-up].



Will the script work on non-chrome browser or do I need to do any tweaks to it?



I have done a 'cache.do', logged-out n logged-in, anything more I need to do?



Thanks in Advance!


andy_dufresne
Tera Expert

I further checked in both mac/windows it works fine on IE, Safari *not* on firefox 😕 strange.  


I'm looking at it for you now. The event.stop() isn't acting in the same way that it does in Chrome.



Give me a sec, I'll get it sorted