I want to hide a text field - for eg. movie_name based on the value of Heirarchichal Select. I have tried using

       $form['field_movie_name']['#states'] =  array (
          'visible' => array (   // action to take.
              'select[name="field_category[und][hierarchical_select][selects][1]"]' => array('value' => '298'),
           ),
        );

in hook_node_form_alter where field_category is the taxonomy field with heirarchichal select. The value to compare is child taxonomy term. Is it possible to use #states or should we use Jquery for it?

Comments

zack.wd created an issue. See original summary.

saurabh.dhariwal’s picture

Yes, it is possible to use #state or jQuery as below code:

1. Using #state code as following:

 $form['field_text']['#states'] =  array (
          'visible' => array (   // action to take.
              ':input[name="field_hierarchical_select[und][hierarchical_select][selects][1]"]' => array('value' => '73'),
           ),
         );

2. Using jquery code to admin theme jquery as below code:

$( document ).ready(function() {
                if($(':input[name="field_hierarchical_select[und][hierarchical_select][selects][1]"]').val() == 73) {
                        $('.node-type-goals #goals-node-form #edit-field-text').show();
                } else {
                        $('.node-type-goals #goals-node-form #edit-field-text').hide();
                }
                $(':input[name="field_hierarchical_select[und][hierarchical_select][selects][1]"]').live('click',function() {
                        if($(this).val() == 73) {
                                $('.node-type-goals #goals-node-form #edit-field-text').show();
                        } else {
                                $('.node-type-goals #goals-node-form #edit-field-text').hide();
                        }
                });
        });

Hope this helps you.

Thanks!

stefan.r’s picture

Status: Active » Needs review

Thanks! @zack.wd does this answer your question?

zack.wd’s picture

I couldn't get #states to work with Heirarchichal Select as you wrote...I had to use the jquery method..anyway thanks @saurabh.dhariwal ..

saurabh.dhariwal’s picture

Glad to hear that any of my provided solution worked for you. Let me know if you face any further Drupal related queries. Ready to help always :)

Thanks
Saurabh

stefan.r’s picture

Status: Needs review » Closed (fixed)
temkin’s picture

See this issue for #states support with HS module.