0

In my situation a person will be editing their record within Channel Form. They have a photo field, but I only want to display it if the person is NOT in a particular category. The categories list has about 50 categories, so if possible, it'd be great to do something like:

{exp:channel:form...}

if category != "bad category"
show field:photo

{/exp:channel:form}

Any ideas on the easiest way to accomplish this? Thanks a million for any tips.

3 Answers 3

1

There's no way to do this with native tags. I think your best bet here, since you're dealing with the the front-end is to use some simple jQuery to show and hide your photo field based on the change event of the dropdown menu.

This is really outside the scope of EE, but it'd look something like this:

$('#id_of_category_field').change(function(){
    var value = $(this).val();

    if(value != 'some-value')
    {
        $('#id_of_photo_field').show();
    }
    else
    {
        $('#id_of_photo_field').hide();
    }
});

This will obviously require a little tweaking for your specific situation, but it should get you going in the right direction.

0
0

Per EE documentation for Channel Form, you should be able to do this using the {category_menu} tag pair:

{exp:channel:form...}

  {category_menu}
    {if category_id != "bad category id"}
      <!-- show field:photo -->
    {/if}
  {/category_menu}

{/exp:channel:form}
1
  • it will not working if entry has multi category - you will have images for each category which is not bad.
    – Max Lazar
    Commented Nov 6, 2013 at 13:00
0

Thanks for all of your tips. The jQuery method seemed to work for me. Channel Form names all category listings as id "categories" and File fields with class "file_field" (I just had one), so everything here apart from my check against the "9" category id is standard Channel Form code. Here's what I did:

    var arr = new Array;
    $("#categories option").each ( function() {
        if (this.selected) {
            arr.push ( $(this).val() );
        }
    });

    if(jQuery.inArray("9", arr) != -1){
         $('.file_field').hide();
         $('#no_photo_message').html("FDN personnel must contact the office manager to change photos.");
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.