drupal:表单API,根据输入动态隐藏或显示字段 [英] drupal: Form API, dynamically hide or show fields based on input

查看:27
本文介绍了drupal:表单API,根据输入动态隐藏或显示字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个表单模块.早期的字段之一是一组单选按钮.默认情况下,第一个按钮被选中.接下来,我将有一系列选择框.一个需要可见,其他需要不可见.然后当用户选择不同的单选按钮时,我希望显示或隐藏不同的选择框.如何在默认情况下隐藏字段和标签并稍后根据选择的单选按钮(或其他选择框选项)显示它?

I'm building a form module. One of the early fields is a set of radio buttons. By default the first button is selected. Next I'll have a series of select boxes. One needs to be visible, the others invisible. Then as the user selects a different radio button I want different select boxes to show or hide. How can I hide the field and label by default and show it later dependent upon which radio button (or another select box option for that matter) is chosen?

推荐答案

您可以使用 #states 属性来实现这一点.#states 属性可以应用于所有表单 API 元素.

You can use the #states property to achieve that. The #states property can be applied to all Form API elements.

这是文档链接一个例子.

这篇关于drupal:表单API,根据输入动态隐藏或显示字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆