开发者

Drupal: make a text field collapsible

开发者 https://www.devze.com 2023-01-31 04:11 出处:网络
Fieldsets in Drupal are collapsible. Is there a simple way to re-cycle this开发者_高级运维 kind of functionality to a text field in a content type?

Fieldsets in Drupal are collapsible. Is there a simple way to re-cycle this开发者_高级运维 kind of functionality to a text field in a content type?

A text field is typically rendered as

 <div class="field field-type-text field-field-my-field">
     <div class="field-label"> My field Label: </div>
     <div class="field-items">
            ....
     </div>
 </div>

Like with a field set, how would one make the field-label clickable to collapse and expand the field-items?

My current avenue of attack is to add the collapsed css class with jQuery when the page is rendered, but am wondering if this kind of thing is already available somehow in the Drupal framework.


This was easier than I thought:

$(document).ready(function() {
      $(".field-field-mytextfield .field-items").css('display','none');
      $(".field-field-mytextfield .field-label").click ( function () 
          { 
            $(this).parent().children( ".field-items").slideToggle('slow');
         } );
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号