Archive Page 2

Vấn đề ajax trong Drupal

Vấn đề ajax trong Drupal
Share
Yesterday at 15:56
Vấn đề:
Khi form được load lần đầu thì với những element được load bằng kĩ thuật ajax thì Form API của Drupal không nhận biết được và sẽ xuất hiện thông báo lỗi “An illegal choice has been detected. when selecting non default xxx” (với xxx là tên của element được load ra từ kĩ thuật ajax).

Điển hình là Ubercart bị lỗi này, xem liên kết phía dưới.

http://www.ubercart.org/forum/bug_reports/10888/illegal_choice_has_been_detected_when_selecting_non_default_country

Lý do:
Do Form API được cache lại, nên lần đầu tiền những element được gọi ra bằng kĩ thuật ajax ko được lưu trong mảng form

Bài viết của Nguyễn Tiến Sĩ

Giải quyết:
Chỉ cần unset những element được load từ ajax và rebuild lại form trước khi submit.

Ví dụ ở đây:

http://randyfay.com/node/33

// HACK: Select values changing never get recognized
unset ($form['howmany']['#value']);

drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

« Previous Page


Status

Error: Please make sure the Twitter account is public.

RSS Drupal Plant


Follow

Get every new post delivered to your Inbox.