Drupal 7 开发内部培训资料, 分头诗人

can't add both #ajax & #process with field_widget_form_alter,but add one can works

赞成!
1
否决!
function camplus_pr_field_widget_form_alter(&$element, &$form_state, $c0ntext) {
  if(isset($element['#field_name']) && $element['#field_name'] == 'field_budget_items') {
    $element['#ajax'] = array(
      'callback' => 'ajax_get_bi_mixable_amount_callback',
      'wrapper' => 'bi_warning',
      'method' => 'replace',
      'effect' => 'fade',
    );
    // if (!isset($element['#process'])) {
    //   $element['#process'] = array();
    // }
    // array_unshift($element['#process'], 'form_process_field_budget_items');
  }
}
function form_process_field_budget_items(&$element) {
  dpm($element);
  return  $element;
}

 

if uncomment ,ajax will not work.why,thanks~

2 个回答

赞成!
0
否决!

试一下process 增加一个function?

e.g.:    

 

'#process' => array('form_process_radios'),

赞成!
0
否决!

不懂!

看了《Drupal 7 First Look》一书,有这样一段:

Displaying fields in forms with field widgets


Widgets are used to display fields within a form. A widget can range from a simple text field that the user can type information into, to complex fields that display calendar controls to site users with complex JavaScript. Really, a widget can be nearly anything you can imagine. A field can either use a custom widget or one of the built-in widgets defined by Drupal. You can create new widgets using    hook_field_widget_info     and you can modify the widgets defined by other modules using hook_field_widget_info_alter. These methods are used to define what field types the widget supports, additional settings that can be used for the widget,and the behaviors that should be used for the widget.


The widgets for an entity are added to a form during a call to field_attach_form.You can alter this process using hook_field_attach_form.