Drupal Example of Ajax on Field group multiple using hook_form_alter

×

Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /var/www/html/drupaldeveloper.in/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseCondition::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 1652 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property MergeQuery::$condition is deprecated in MergeQuery->__construct() (line 1344 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).
  • Deprecated function: Creation of dynamic property DatabaseCondition::$stringVersion is deprecated in DatabaseCondition->compile() (line 1865 of /var/www/html/drupaldeveloper.in/includes/database/query.inc).

This CodeLet let you konw how to implement ajax on field group multiple module.
"fgm_node_YOURNODE_form_group_YOURGROUPNAME" where "YOURNODE" will be the name of your content type and "YOURGROUPNAME" will be the name of your field group,
Given example is for text field, ajax call on blur event.

Drupal use fo ajax on field group multiple module
CodeLet: 

<?php
function mymodule_form_alter(&$form, $form_state, $form_id) {

if($form_id == 'group_node_form'){

$ar__field_item = $form['fgm_node_YOURNODE_form_group_YOURGROUPNAME']['fields']['items'];
// here content type is sales and group name is sl_multiple_product_group
foreach ($ar__product_item as $key => $value) {
$form['fgm_node_sales_form_group_sl_multiple_product_group']['fields']['items'][$key]['field_sl_quantity']['und']['value']['#ajax'] = array(
'callback' => 'get_unit_price',
'wrapper' => 'unit_price_callback_replace_' . $key,
);
$form['fgm_node_sales_form_group_sl_multiple_product_group']['fields']['items'][$key]['field_sl_product_price']['und']['value']['#ajax'] = array(
'callback' => 'get_unit_price',
'wrapper' => 'unit_price_callback_replace_' . $key,);

$form['fgm_node_sales_form_group_sl_multiple_product_group']['fields']['items'][$key]['field_sl_unit_price']['und']['#suffix'] = 'unit price will be here';

}

}

}

/**
* ajax call back
*/

function get_unit_price($form, $form_state) {
$ar__product_item = $form_state['values']['fgm_node_sales_form_group_sl_multiple_product_group']['fields']['items'];
$arr__ajax_replace = array();
foreach ($ar__product_item as $key => $value) {

$sn__quantity = $form_state['values']['fgm_node_sales_form_group_sl_multiple_product_group']['fields']['items'][$key]['field_sl_quantity']['und']['value'];
$sn__price = $form_state['values']['fgm_node_sales_form_group_sl_multiple_product_group']['fields']['items'][$key]['field_sl_product_price']['und']['value'];
$sn__unit_price = $sn__quantity * $sn__price ;
$arr__ajax_replace[$key] = ajax_command_replace('#unit_price_callback_replace_' . $key, '' . $sn__unit_price . '');
}

return array(
'#type' => 'ajax',
'#commands' => $arr__ajax_replace
);

}

?>

Compatibility: 
Is CodeLet useful?: 
Drupal Example of Ajax on Field group multiple using hook_form_alter | Drupal Developer

Error

The website encountered an unexpected error. Please try again later.