【问题标题】:Manipulate form element in Drupal 8在 Drupal 8 中操作表单元素
【发布时间】:2016-07-03 19:20:21
【问题描述】:

我有一个非常简单的 Drupal 8.0.1 表单,它即将变得非常复杂。

该表格用于填写数据以获取银行贷款。

我有名字、姓氏、街道等,它工作得很好。 现在我需要实现一个co debitor,其中包含名字、姓氏、街道等。

但是...共同借方的字段可能只有在访问者选中复选框时才有效...

在 Drupal 8 中使用新的 Ajax 设置我该怎么做呢?

我是 Drupal 6 和 Ahah 的冠军,但 D8 对我来说是一个全新的世界......

感谢您的宝贵时间。

问候,拉斯

【问题讨论】:

    标签: forms drupal-8


    【解决方案1】:

    如果我理解正确,请执行以下操作:

    $form['co_debitor'] = array(
      '#type' => 'checkbox',
      '#title' => t('Add Co-Debitor'),
      '#default_value' => FALSE
    );
    
    $form['co_debitor_firstname'] = array(
      '#type' => 'textfield',
      '#title' => t('First name of the co-debitor'),
      '#states' => array(
        // Only show this field when the 'co_debitor' checkbox is checked.
        'visible' => array(
          ':input[name="co_debitor"]' => array('checked' => TRUE),
        ),
      ),
    );
    

    现在名字字段应该只有在选中复选框时才可见。让我知道这是否是您想要的。

    【讨论】:

    • 嗨弗兰克,非常感谢! :-)
    猜你喜欢
    • 2020-02-24
    • 2020-11-13
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多