PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Pass 'disabled' to gform_pre_render_2 for dynamically populated dropdown

  1. Based on the post about populating a dropdown dynamically, I have a drop down that pulls from my CATEGORIES, from which I want the user to be able to select ONLY a category that has parent (e.g. If i have men, women and children as parent categories, and each of them contains "clothes" and "shoes" I want the user to only be able to select either Men > Clothes or Men > Shoes, but not just MEN. I'm passing the correct values to form and it's picking them up, but I can't figure out how to indicate which values (the parent categories) should be disabled/unavailable for the user to select. Thanks. /sarah

    Posted 12 years ago on Tuesday October 11, 2011 | Permalink
  2. Hi Abacus,

    You could check if the current category in the loop as any children and if so, skip it and move on the next category.

    [php]
    $children = get_categories(array('child_of' => $category->term_id));
    if(!empty(children))
        continue;
    Posted 12 years ago on Tuesday October 11, 2011 | Permalink
  3. Hi.. I want to SHOW the parent category, just not allow it to be selected. This would just not show the parent category at all, right?

    Posted 12 years ago on Tuesday October 11, 2011 | Permalink
  4. Hi Abacus,

    Ah, I see. That makes this a little trickier. What you could do is the same check, but instead of skipping the parent category, you would set the value to a special key, like "CAT_PARENT". Then you could use a little jQuery like this to disable those elements:

    [js]
    <script type="text/javascript">
        jQuery(document).ready(function($){
    
            $('.populate-cats option[value="CAT_PARENT"]').attr('disabled', true);
    
        });
        </script>
    Posted 12 years ago on Tuesday October 11, 2011 | Permalink