diff --git a/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module b/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module index e719bb5..6954ac1 100644 --- a/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module +++ b/web/modules/custom/figli_compta_ledger/figli_compta_ledger.module @@ -122,6 +122,16 @@ function figli_compta_ledger_validate_repartition(array &$form, FormStateInterfa function figli_compta_ledger_node_form_ajax_submit(array $form, FormStateInterface $form_state) { $response = new AjaxResponse(); if ($form_state->getErrors()) { + // The re-rendered form below does mark every répartition row with an + // `error`/`has-error` CSS class (a subtle red outline), but + // setErrorByName()'s message text itself has nowhere to render -- + // that normally goes through the page's status-messages region, + // which isn't part of this standalone AJAX-replaced form fragment. + // Without this, the message was silently discarded: the modal just + // stayed open with reddened fields and no visible explanation. + foreach ($form_state->getErrors() as $error) { + $response->addCommand(new MessageCommand($error, NULL, ['type' => 'error'], FALSE)); + } unset($form['#prefix'], $form['#suffix']); $response->addCommand(new ReplaceCommand('#' . $form['#id'], $form)); return $response;