Ato*_*mox 2 ajax drupal drupal-fapi
问题:
在Drupal 7的Form API中,当使用#AJAX刷新字段时,在刷新整个页面之前,不会显示验证中的错误消息.我看到我刷新的字段在错误状态中突出显示,但用户没有看到相关的消息,直到它为时已晚(他们重新加载页面,或转到另一页).
我开始在这个庄园中手动处理错误堆栈:Drupal.org - 在验证过程中筛选出特定的错误,但我有一个复杂的表单,并且有足够的时间来完成此任务.必须有一些方法来刷新堆栈并向用户显示消息,而无需手动处理所有内容.
注意:我正在使用带有回调的多命令,因此使用它是我的选择.
$commands[] = ajax_command_replace("#my_wrapper", render($form['test']['field_a']));
$commands[] = ajax_command_replace("#another_wrapper", render($form['test']['field_b']));
return array('#type' => 'ajax', '#commands' => $commands);
Run Code Online (Sandbox Code Playgroud)
思考?
解:
显然,当您使用多回调方法时,Drupal不会为您刷新消息.您可以手动执行此操作,如下所示:
// Remove the old messages div, clearing existing messages.
$commands[] = ajax_command_remove('#messages');
// Append a new messages div with our latest errors and messages.
$commands[] = ajax_command_after('#header-region', '<div id="messages">' . theme('status_messages') . '</div>');
Run Code Online (Sandbox Code Playgroud)
只需将其添加到您拥有的任何回调命令[]数组中,就可以了.
感谢Drupal.org -正确方向的AJAX命令和Drupal消息!
| 归档时间: |
|
| 查看次数: |
4227 次 |
| 最近记录: |