【问题标题】:Drupal 7 form ajax callback show no radio itemsDrupal 7 表单 ajax 回调显示没有单选项目
【发布时间】:2014-03-17 19:55:19
【问题描述】:

我在使用 drupal 7 并形成 ajax 回调时遇到问题。

我有带有 form select 项的简单表单,当我选择带有 form radios 的 ajax 回调显示项时。它确实有效,但我只得到无线电项目 titledescription 但没有可供选择的选项。

function my_test_form($form, &$form_state) {
  $form['places'] = array(
    '#type' => 'select',
    '#title' => t('Select twitter trends location'),
    '#options' => array('1' => 'item 1', '2' => 'item 2'),
    '#default_value' => 1,
    '#description' => t('Select description'),
    '#ajax' => array(
      'callback' => 'my_test_form_callback',
      'wrapper' => '.form-item.form-type-select.form-item-places',
      'method' => 'append',
      'effect' => 'fade',
    ),
  );
  return $form;
}


function my_test_form_callback($form, &$form_state) {
  $form['trends'] = array(
    '#type' => 'radios',
    '#title' => t('Select'),
    '#options' => array(0 => t('Closed'), 1 => t('Active')),
    '#default_value' => 0,
    '#description' => t('Radios description.'),
  );
  return $form['trends'];
}

打印结果 $form['trends'] -> dpm(drupal_render($form['trends']));

<div class="form-item form-type-radios">
  <label>Select trend </label>
  <div class="form-radios"></div>
  <div class="description">Radios description.</div>
</div>

我会很高兴收到每一个建议。 非常感谢。

【问题讨论】:

    标签: ajax drupal drupal-7 radio-button drupal-forms


    【解决方案1】:

    回调接收一个构建的表单。它只负责返回表单的正确部分。

    function my_test_form_callback($form, &$form_state) {
      return $form['trends'];
    }
    

    my_test_form 负责为第一次调用和所有后续 AJAX 调用构建表单。只需将您的条件放在此函数中即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多