public function StatisticsPageTrait::updateTrainingProgressAjax in Opigno statistics 3.x
Ajax form submit callback.
Parameters
array $form: The form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
Return value
\Drupal\Core\Ajax\AjaxResponse The updated progress element.
File
- src/
StatisticsPageTrait.php, line 533
Class
- StatisticsPageTrait
- Common helper methods for a statistics pages.
Namespace
Drupal\opigno_statisticsCode
public function updateTrainingProgressAjax(array &$form, FormStateInterface &$form_state) : AjaxResponse {
$trigger = $form_state
->getTriggeringElement();
// Select the 1st available month when the year is changed.
if (isset($trigger['#name']) && $trigger['#name'] === 'year') {
$months = $form['trainings_progress']['month']['#options'];
$form['trainings_progress']['month']['#value'] = array_key_first($months);
}
// Update the training progress and inintialize the bootstrap selects.
$id = $form['trainings_progress']['#attributes']['id'];
$response = new AjaxResponse();
$response
->addCommand(new InvokeCommand('body', 'removeClass', [
'charts-rendered',
]));
$response
->addCommand(new ReplaceCommand("#{$id}", $form['trainings_progress']));
return $response;
}