目的:
AJAXオートコンプリートとTableselectフォームを組み合わせて、ユーザーがDrupalサイト内の既存の製品と一致しないインポートされた製品を選択するためのキーを作成します。この新しい請求モジュールは、特定のサードパーティの請求サービスの使用を可能にします。
問題:
AJAX行を介して挿入された値を返す次のコードを取得できません。配列は、行の配列キーをキーと値の両方として送り返し続けます。これが元のコードです選択は次のとおりです。
そしてここに戻り値があります:
ご覧のとおり、選択された行の戻り値には配列キーがリストされていますが、選択されていない行の値は0です。
質問:戻り値をどのように変更して、それがmy AJAX form field?)で選択された値になるようにしますか?
function Test_product_form($form, &$form_state)
{
$form_state['page_num'] = 2;
$form['Markup'] = array(
'#markup' => t('Please select and synchronize Test Subscription Offers with your Drupal Commerce Product SKUS below:') . '</br>' . '</br>'
);
foreach ($form_state['sub_offers'] as $key => $offer) {
if ($offer['Status'] == 'Active') {
$product = commerce_product_load_by_sku($offer['OfferCode']) ? commerce_product_load_by_sku($offer['OfferCode']) : FALSE;
if ($product === FALSE) {
$rows[] = array(
'Test Subscription Offers' => array(
'data' => $offer['OfferCode'],
'id' => 'row' . $key . '-aso',
'class' => 'col-aso'
),
'Drupal Product SKUS' => array(
'data' => array(
// drupal_get_form('commerce_product_line_item_add_form'),
'#type' => 'textfield',
'#title' => t('Product SKU'),
'#description' => t('Enter the SKU of the product to add to the order.'),
'#autocomplete_path' => 'commerce_product/autocomplete/commerce_product/line_item_product_selector/product',
'#size' => 60,
'#maxlength' => 255,
//In order for AJAX within the Rows of tableselect form you must declare the
'#id' => $key . 'product_textfield'
),
'id' => 'row' . $key . '-dps',
'class' => 'col-dps'
)
);
} else {
$rows[] = array(
'Test Subscription Offers' => array(
'data' => $offer['OfferCode'],
'id' => 'row' . $key . '-aso',
'class' => 'col-aso'
),
'Drupal Product SKUS' => array(
'data' => array(
'#type' => 'link',
'#title' => $product->sku,
'#href' => 'admin/commerce/products/' . $product->product_id
// '#options' => $l_options,
// '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
),
'id' => 'row' . $key . '-dps',
'class' => 'col-dps'
)
);
}
}
}
$hinput = array(
'Test Subscription Offers' => 'aso',
'Drupal Product SKUS' => 'dps'
);
foreach ($hinput as $hkey => $hvalue) {
$header[$hkey] = array(
'data' => $hkey,
'id' => 'head-' . $hvalue,
'class' => 'col-' . $hvalue
);
}
$options = array();
foreach ($rows as $key => $row) {
$options[$key] = array(
'Test Subscription Offers' => $row['Test Subscription Offers'],
'Drupal Product SKUS' => $row['Drupal Product SKUS']
);
}
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
//'#js_select' => TRUE,
'#multiple' => TRUE
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#submit' => array(
'Test_payment_submit_step_two'
),
'#validate' => array(
'Test_payment_validate_step_two'
)
);
ddl_once($form);
return ($form);
}
短い答え:フォーム要素の送信にtableselectを使用することはできません。
より長い答え:tableselectは、さらに処理するために1つまたは複数rowsを選択するためのものです。これは、各rowに対して1つの値のみを受け取る送信ハンドラーで確認できます。
http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#tableselect を参照してください(これは http:// drupalの完全な例にリンクしています) .org/node/945102#drupal7 )。
本当にテーブルフォームが必要な場合は、dwillcoxの提案を使用して、テーマ関数を使用してフォームを説明どおりにレンダリングすることができます http://drupal.org/node/1587968
よくわかりませんが、1つのページに複数のフォームがあることを考えましたか?つまり、テーブル選択試行の各行には独自の形式があります。これを機能させるには、 hook_forms() を実装する必要があります。これを annotate module に使用しました。
Tableselectとフォームのテーマ設定に関するいくつかの引数:
いくつかはあなたのコードを細かく選んだ:
あなたが取った解決策を教えてください。