markdown Drupal有条件地显示/隐藏字段。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Drupal有条件地显示/隐藏字段。相关的知识,希望对你有一定的参考价值。

# Drupal conditionally show/hide fields.

This needs to be done in a custom module. Anything that effects the CMS side of things needs to be done in a custom module. If you try to do it in `themes/custom/themname` it won't work. You can only do front end facing stuff there.

Referencing the code below.

1. Make a form array for the field you want to show hide.
2. In the form array do a `#states` array.
3. Add in the state you want to change.The example is using `invisible`.
4. Do a associative array. The left is a jquery-like selecter. The right is the state of that selector that triggers the `invisible` state.

```
// Hide name field when the anonymous checkbox is checked.
$form['name'] = array(
  '#type' => 'textfield',
  '#title' => t('Name'),
  '#states' => array(
    'invisible' => array(
      ':input[name="anonymous"]' => array('checked' => TRUE),
    ),
  ),
);
```

## Reference
[https://www.lullabot.com/articles/form-api-states](https://www.lullabot.com/articles/form-api-states)

以上是关于markdown Drupal有条件地显示/隐藏字段。的主要内容,如果未能解决你的问题,请参考以下文章

如何有条件地隐藏或显示剑道网格​​中的列

如何在 MongoDB 中有条件地显示/隐藏字段

有条件地显示和隐藏表单字段并设置字段值

drupal:表单 API,根据输入动态隐藏或显示字段

Jquery .toggle 只显示不隐藏在 Drupal 视图中

Excel - 有条件地隐藏错误