0

I am working on a Drupal site and I want to add a checkbox within a content type that will hide an object if checked.

I am not to worried about how to hide it, I can figure that out with Js or CSS later on but I need to know how to add a checkbox that has the ability to modify the display.

I think its going to be along the lines of adding a new field but I don't know what type of field to add.

Any help is greatly appreciated :)

Clinton Green
  • 9,697
  • 21
  • 68
  • 103
  • possible duplicate of [drupal: Form API, dynamically hide or show fields based on input](http://stackoverflow.com/questions/12753010/drupal-form-api-dynamically-hide-or-show-fields-based-on-input) – Muhammad Reda Aug 18 '14 at 07:50

1 Answers1

1

I have done this by adding form alter,

You need to write the form alter then you can add states property for the field you need to show or hide

$form['your_showhide_field']['#states'] = array(
            'visible' => array(
                ':input[name="you_checkbox_name"]' => array('checked' => true),
            ),
        );

OR

You can also use field condition state module to do this.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
JSunny
  • 477
  • 2
  • 7