Autofill Category

This topic contains 14 replies, has 4 voices, and was last updated by  Paolo 8 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #44631

    stephanfo
    Expired Member
    Post count: 19

    Hi All,

    I would like to know if it is possible to “Autofill” the category taxonomy, depending on the plan selected with the plugin “Prices & Payement”.

    In my case, the “Plans” and “Category” (Taxonomy”) are redondant, and visitor need to fill 2 times the same information.

    Thank you.
    Stef.

    #44642

    Guust
    Moderator
    Post count: 29970

    I am not sure I understand completely.
    You can restrict price packages to some categories only, so users cannot add to a particular category if they choose a particular price package.
    The category select on the Add Listing form can be restricted by the price package, but cannot be auto-selected.
    Users need to select a price package BEFORE adding the information.

    #44668

    stephanfo
    Expired Member
    Post count: 19

    Hi,

    The problem I face is the following. I have two categories (simple example: Hotel / Restaurant). These both categories have specific custom fields. In order to only show the appropriate custom fields (depending on the category), I have to set up 2 plan with “Prices & Payment” plugins (without any price). This idea as been given in the following post : Custom fields only visible with some categories.

    Now, the problem is that I have to select plan Hotel or Restaurant (from Price & Payment plugin), this correctly select the right customs fields to show when entering the new place and in the front end after. But I have to select in the category field Hotel or Restaurant another time (first time was when selecting the plan). I really need to select the categories, as this is showed in the map (to select if you want to see only Restaurant or Hotel on the map in this example).

    I would prefer that when I select the plan, automatically the category field is loaded with default values accordingly to the plan, and if everything work, to finally hide the field when entering a new place.

    Maybe there is another solution I missed, do not hesitate if you have another way to solve my issue.

    Thank you for your support.
    Stef.

    #44670

    Guust
    Moderator
    Post count: 29970

    You need to restrict the price packages to one of the categories only.
    Then you need to link to the packages directly, and hide the packages from the Add Listing form.
    If you post your URL and admin details, I will be able to check and advise better.

    #44682

    Paolo
    Site Admin
    Post count: 31206

    I think having the category auto-selected should feasible with a jQuery function, but I’m not good enough with jQuery, so I need to pass the ball to Stiofan.

    We’ll let you know,

    Thanks

    #44691

    stephanfo
    Expired Member
    Post count: 19

    Hi,

    Thank you for your message. The best would be a way to not use the Plan, and to only show/hide the custom fields in live, depending on the categories you select (as explained in my link above). That would be the best solution from my perspective.

    Else, you are right, the JQuery could be the solution.

    Thanks.

    #44692

    stephanfo
    Expired Member
    Post count: 19

    Or is there a way to pre-load the categories by the link, as we can do to select the plan?

    For example: http://www.foo.com/add-listing/?listing_type=gd_place&package_id=2&category%5B%5D=hotel&category%5B%5D=restaurant

    Thanks

    #44750

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hello, this is a javascript snippet that would set the category id 8 selected when price package 3 is seleted.

    
    
    jQuery(document).ready(function(){
    
    $price_id = jQuery('[name="package_id"]:checked').val();
    
    if($price_id==3){
    jQuery('#gd_placecategory.chosen_select').val('8').change();
    }
    
    });

    Hopefully u can get it from that, let us know if you need more.

    Stiofan

    #44753

    stephanfo
    Expired Member
    Post count: 19

    It does exactly what I expect. Thank you so much Guust/Paolo/Stiofan. You are the boss ;-).

    Stef.

    #44755

    stephanfo
    Expired Member
    Post count: 19

    Hi again,

    I wrote the following code in GDF Option/Quick Code, according to your example:

    
    
    jQuery(document).ready(function(){
        
        if(location.pathname == "/add-listing/")
        {
            $price_id = jQuery('[name="package_id"]:checked').val();
    
            if($price_id == 1)
            {
                jQuery('#gd_placecategory.chosen_select').val('8').change();
                jQuery('#gd_placecategory.chosen_select').val('7').change();
                //jQuery('input[name = post_default_category], [value = 8]').attr("checked", "checked");
            }
        
            if($price_id == 2)
            {
                jQuery('#gd_placecategory.chosen_select').val('7').change();
                //jQuery('input[name = post_default_category], [value = 7]').attr("checked", "checked");
            }
            
        }
    
    });

    Adding the good categories works like a charm. I would like also to be able to select the default category for both case. As far as I understand, this is an AJAX loading, and I do not know how to detect the adding of the node ‘input[name = post_default_category], [value = 7]’, or identify & wait for the ajax request to finish.

    Any idea?

    Thank you so much.
    Stef.

    #44756

    stephanfo
    Expired Member
    Post count: 19

    I thought to insert a code like this before to change the “chosen_select”, but it doesn’t trigger.

    
    
    jQuery(document).on('DOMNodeInserted', 'input[name = post_default_category], [value = 7]', function (e)
    {
        jQuery('input[name = post_default_category], [value = 7]').attr("checked", "checked");
    });
    #44781

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    You could try a setTimeout (not tested)

    
    
    setTimeout(function(){
     jQuery('input[name = post_default_category], [value = 7]').attr("checked", "checked");
    
    }, 2000);

    Stiofan

    #44864

    stephanfo
    Expired Member
    Post count: 19

    I was thinking about this way, but it is not fully perfect, as we never know if the ajax will be loaded in 2 seconds. But this will work most of the time I guess.

    Thank you Stiofan.

    #45177

    stephanfo
    Expired Member
    Post count: 19

    If this can help someone else, below my final code.

    JS Code:

    
    
    jQuery(document).ready(function(){
        
        if(location.pathname == "/add-listing/")
        {
            $price_id = jQuery('[name="package_id"]:checked').val();
    
            if($price_id == 1)
            {
                jQuery('#gd_placecategory.chosen_select').val('8').change();
                setTimeout(function()
                {
                    jQuery('input[name = post_default_category][value = 8]').attr("checked", "checked");
                }, 2000);
    
            }
        
            if($price_id == 2)
            {
                jQuery('#gd_placecategory.chosen_select').val('7').change();
                setTimeout(function()
                {
                    jQuery('input[name = post_default_category][value = 7]').attr("checked", "checked");
                }, 2000);
            }
            
        }
    
    });

    CSS Code:

    
    
    #gd_placecategory_row{
        display: none;
    }

    Thank you again geo team.
    Stef.

    #45179

    Paolo
    Site Admin
    Post count: 31206

    Thank you for sharing! 🙂

Viewing 15 posts - 1 through 15 (of 15 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket