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

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

问题描述

我正在建立一个表单模块。早期的领域之一是一套单选按钮。默认情况下,第一个按钮被选中。接下来我会有一系列选择框。一个需要可见,其他人看不见。然后当用户选择不同的单选按钮时,我想要不同的选择框显示或隐藏。默认情况下,如何隐藏字段和标签,稍后再显示,取决于选择哪个单选按钮(或其他选择框选项)?

解决方案

您可以使用 #states 属性来实现。 #states 属性可以应用于所有Form 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?

解决方案

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

Here's the documentation link with an example.

Hope this helps... Muhammad.

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

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