Autofill Category
This topic contains 14 replies, has 4 voices, and was last updated by Paolo 9 years, 5 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
July 3, 2015 at 9:17 pm #44631
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.July 3, 2015 at 11:21 pm #44642I 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.July 4, 2015 at 9:32 am #44668Hi,
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.July 4, 2015 at 11:13 am #44670You 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.July 4, 2015 at 3:55 pm #44682I 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
July 4, 2015 at 9:52 pm #44691Hi,
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.
July 4, 2015 at 9:58 pm #44692Or 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
July 5, 2015 at 6:10 pm #44750Hello, 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
July 5, 2015 at 7:48 pm #44753It does exactly what I expect. Thank you so much Guust/Paolo/Stiofan. You are the boss ;-).
Stef.
July 5, 2015 at 8:57 pm #44755Hi 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.July 5, 2015 at 9:05 pm #44756I 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"); });
July 6, 2015 at 9:55 am #44781You could try a setTimeout (not tested)
setTimeout(function(){ jQuery('input[name = post_default_category], [value = 7]').attr("checked", "checked"); }, 2000);
Stiofan
July 6, 2015 at 9:16 pm #44864I 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.
July 9, 2015 at 7:17 pm #45177If 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.July 9, 2015 at 7:57 pm #45179Thank you for sharing! 🙂
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket