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.

这是文档链接一个例子.

相关文章