【问题标题】:Drupal - #states visible option not working with the date typeDrupal - #states 可见选项不适用于日期类型
【发布时间】:2011-06-21 17:43:26
【问题描述】:

我正在尝试为显示小时数的 Drupal 模块创建过滤表单。我正在尝试获取一个日期字段以仅显示用户是否要对其进行过滤。我在隐藏的代码中有一个文本字段。我不确定我应该怎么做。这是我的字段代码:

$form['filters']['start-do'] = array(
    '#type' => 'checkbox',
    '#title' => t('Filter by start date'),
);

$form['filters']['start'] = array(
    '#type' => 'date',
    '#title' => t('Start Date'),
    '#description' => t('Show hours that started after this date.'),
    '#states' => array(
        'invisible' => array(
            ':input[name="start-do"]' => array('checked' => FALSE) 
        )    
    )
);

【问题讨论】:

    标签: forms drupal date


    【解决方案1】:

    您忘记了示例中的“容器”类型表单元素。

    试试这样的:

    $form['filters']['start-do'] = array(
      '#type' => 'checkbox',
      '#title' => t('Filter by start date'),
    );
    $form['filters']['container'] = array(
      '#type' => 'container',
      '#states' => array(
        'invisible' => array(
          'input[name="start-do"]' => array('checked' => FALSE)
        )
      )
    );
    $form['filters']['container']['start'] = array(
      '#type' => 'date',
      '#title' => t('Start Date'),
      '#description' => t('Show hours that started after this date.'),
    );
    

    查看表单 API 参考总是值得的:http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/7#states

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 2016-10-11
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多