2
所以這裏就是我想要做的事:如何讓Drupal將AHAH行爲添加到通過AHAH返回的表單元素?
1.創建並呈現以下表單元素:
$form['rb_download_' . $doc_id] = array(
'#type' => 'submit',
'#name' => 'doc_' . $doc_id,
'#prefix' => "<div id='rb_doc_order_{$doc_id}'>",
'#suffix' => '</div>',
'#value' =>variable_get('rb_order_button', "buyOnline"),
'#ahah' => array(
'event' => 'click',
'path' => "rb/case/doc_order_js/$case->nid/$doc_id",
'wrapper' => "rb_doc_order_{$doc_id}",
'effect' => 'fade',),
);
2.動作函數返回,並用替代上面的元素新元件:
function rb_case_doc_order_js($case, $doc_id) {
$button['rb_download_' . $doc_id] = array(
'#type' => 'submit',
'#name' => 'doc_' . $doc_id,
'#prefix' => "<div id='rb_doc_order_{$doc_id}'>",
'#suffix' => '</div>',
'#value' => variable_get('rb_order_confirm', "Remove from cart"),
//'#attributes' => array('class' => 'ahah-processed'),
'#ahah' => array(
'event' => 'click',
'path' => "rb/case/doc_unorder_js/$case->nid/$doc_id",
'wrapper' => "rb_doc_order_{$doc_id}",
'effect' => 'fade',),
);
$output .= drupal_render($button);
$output .= "<script type='text/javascript'>\n";
$output .= "cart_block_item_count($count);\n";
$output .= "Drupal.ahah;\n";
$output .= "</script>\n";
print drupal_json($output);
}
3.結果,舊的按鈕由上面的一個代替,但是新按鈕不是AJAX
啓用。
我需要做什麼才能使新的返回元素AHAH
準備好?