drupal-7 - Drupal 7 表单 API : Set visible state of form element based on OR instead of AND

标签 drupal-7 drupal-modules drupal-forms

我只有在选择框中选择了一些选项之一时,我才想显示一个字段集。问题是,我似乎看不到如何使用 OR。如果您在数组中包含多个条件,它会像 AND 一样操作。例如,如果选择框的值为 1 2 或 3,我需要它来工作。

最佳答案

显然从 drupal 7.14 开始支持“或”和“异或”。它只是不在文档中任何容易找到的地方。这是我做的一个例子,以防有人需要它。这行得通。

$form['survey'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
    '#states' => array(
        'visible' => array(
            array(
                array(':input[name="measurementmethod"]' => array('value'=>'5')),
                'xor',
                array(':input[name="measurementmethod"]' => array('value'=>'6')),
                'xor',
                array(':input[name="measurementmethod"]' => array('value'=>'7'))
            )
        )
    )
);

关于drupal-7 - Drupal 7 表单 API : Set visible state of form element based on OR instead of AND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12791101/

相关文章:

php - 在 drupal 7 中的 block 内创建自定义表单

css - drupal 7 chrome 不加载 css 规则

drupal-7 - 使用 Managed_file 以自定义形式上传多个文件

javascript - 如何为 Drupal 7 应用 IE7 的条件 css?

mysql - Drupal 7 PDOException : SQLState[42S22], 未知字段

drupal - 如何覆盖另一个模块中存在的函数

组中的 drupal 7 form_alter 配置文件字段

drupal-7 - 如何以编程方式从 Views 3 中删除字段?

drupal - 匿名用户 : You are not authorized to access this page. 权限正常

php - Drupal 7默认用户注册表单如何实现多步