Preselected Category for Search

Discussion in 'Modules / Plugins / Modifications' started by Eric Barnes, Sep 19, 2008.

  1. Eric Barnes Guest

    It seems to be a common change to want a category to be pre-selected when visiting the search form. This modification will allow that.

    V4.0.x

    #1. Open search.tpl and find the closing </form> tag.

    #2. Just below it add:
    Code:
    {literal}
    <script type="text/javascript">
        selectedCat(1); //where 1 is the category pre selected.
        function selectedCat(type){
            document.getElementById('ajxresponse').innerHTML = '';
            var QSTRING = type;
            cp.call('{/literal}{$smarty.const.URL}{literal}/ajax.php', 'ajax_extra_search_fields', response, QSTRING);
            return false;
        }
    </script>
    {/literal}                                         
    
    Please keep in mind you can only have one preselected and in this example the category had an id of 1.

    V4.1.x Beta
    #1. Open search.tpl and find the following code:
    Code:
    $(document).ready(function() {
    
    #2. Just below it add:
    Code:
    selectedCat(1); //where 1 is the category pre selected.
        function selectedCat(type){
            $("#response").show()
            $.ajax({
                url: 'ajax.php',
                data: 'action=extra_listing_fields&do=search§ion=' + type,
                type: 'post',
                success: function (msg) {
                    $("#response").html(msg);
                }
            });
        }                                    
    
    Please keep in mind you can only have one preselected and in this example the category had an id of 1.
  2. seymourjames All Hands On Deck

    That is a nice mod and useful. Is there a way to get the same action if the same extrafields apply to all categories. In other words, the extrafields drop down automatically by default?

    At present, if the mod is applied to the search form, the select all comes up by default (regardless of the cat id put in) and the extrafields drop down (the right action for my need), if you then do a search on a specific category it is fine also but then if you go back and 'select all' without refreshing the page, the extrafields in the search form disappear. Logic which is something like if select all then drop the extrafields.
  3. DGiscombe Graphic / Web Desginer

    Hi Eric,

    Is there a different code to use for v4.1.0 Beta 5 which has the same outcome.

    Reason why I would like this is because the searchable date field only works on this version and that is the one I'd like to target for the search without having to select a category first.

    This question is open to anyone of course.
  4. Eric Barnes Guest

    Yes it would be different code. I will have to do some testing on it before I can post the change.
  5. DGiscombe Graphic / Web Desginer

    Excellent.

    Thanks Eric, got something to tell my client now
  6. Eric Barnes Guest

    I just edited the first post in this topic with instructions for v4.1 beta.
  7. DGiscombe Graphic / Web Desginer

    Genius!

    I've now stripped out the option box all together so that it only shows "starts from" and the search button. If I get the calendar to stay there instead of popping up, that can be my 'bare bones' event calendar.

    Thank you very much Eric.
  8. naidu01 Customer

    Can this be modified to autoselect category

    Hello Eric,
    I added this code to a search box that I added to the left menu. Can this script be modified to auto-select the category/subcategory that the user has clicked into?
  9. Bone Customer

    Preselected category produces error

    I made the modification to the search.tpl from templatecodes 3 column template system and it loaded the page with errors.
    The when a category is selected from category dropdown, none of the category specific extra fields show.
    Is this code / modification valid for 4.1.6 Developer editions using templatecodes template?
  10. seymourjames All Hands On Deck

    I see no reason why it should not work if indeed it does work for 4.1.6. Try it on the default template (search.tpl) and see if it works. The only difference in the search.tpl file supplied by templatecodes is the styling of it. No structural change has been made.

    If it does not work on the default template it is then a case of it does not work or you have not implemented the modification correctly. Let us know.
  11. seymourjames All Hands On Deck

    Well I just tried it and it kind of works on the evo template (same issue on the default template). It recognizes the category fine and drops the appropriate extrafields.

    What it does not do however is change the label inside the category dropdown box - it still says search all.
  12. Bone Customer

    I managed to get it working as well, and have the same effect with search all.
    I will work on this and post a fix. Thanks for looking into this seymourjames.
  13. guillopuig Customer

    Newbie question.

    Can I use this for one single category in one single category specific browse page w/o it changing the normal behavior of other search forms?

    Specifically, can I include it above, say, automobile browse page or real estate browse page(or both), for the search to only work on that category?

    (im not sure if I explained my question correctly), please let me know.

    Thanks!
  14. guillopuig Customer

    As I figured...


    Can I use a separate search module for any category of my choosing w/o it changing the behavior of the other search boxes in the script? I guess something like the featured listings plugin where you specify the category.

    Sorry, I might have missed the answer within the thread.

Share This Page