【问题标题】:tableselect make specific checkbox checkedtableselect 选中特定复选框
【发布时间】:2019-08-04 09:23:29
【问题描述】:
foreach ($courses as $user) {
    $options[$user['uid']] = [
        'coursecode'  => $user['coursecode'],
        'coursename'  => $user['coursename'],
        'credithours' => $user['credithours'],
        'coursetype'  => $user['coursetype'],
        'building'    => $user['building'],
        'place'       => $user['place'],
        'day'         => $user['day'],
        'time'        => $user['time'],
    ];
}
$form['table'] = [
    '#type'       => 'tableselect',
    '#header'     => $header,
    '#options'    => $options,
    '#empty'      => t('No Courses found'),
    '#js_select'  => false,
    '#attributes' => ['checked' => 'checked'],
];

此代码生成我可以注册的所有课程是否有任何方法可以检查特定值作为默认值,我在选中特定复选框时遇到问题

所以有什么帮助吗? 我正在使用 drupal 8

【问题讨论】:

    标签: php forms symfony drupal drupal-8


    【解决方案1】:

    //在你的foreach循环中

    foreach($courses as $user) {
      $default_value[$user['uid']] = 1; // use 1 or 0 as appropriate
    
    }
    

    // 现在用你的表选择

    $form['table']['#default_value'] = $default_value;
    

    // 每个选项都没有提供默认值,而是在 tableselect 主数组中提供了一个默认值数组。

    希望这能解决您的问题。

    【讨论】:

      猜你喜欢
      • 2020-10-31
      • 1970-01-01
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 2019-09-02
      相关资源
      最近更新 更多