From 852eda205664174c9635b671d6942737e7a8af20 Mon Sep 17 00:00:00 2001 From: bach Date: Sat, 5 Sep 2026 22:08:42 +0200 Subject: [PATCH] =?UTF-8?q?Show=20the=20r=C3=A9partition=20validation=20er?= =?UTF-8?q?ror=20message=20instead=20of=20failing=20silently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Editing a ligne_comptable with an inconsistent répartition correctly blocked the save (setErrorByName() on field_repartition), but the message text had nowhere to render: it normally goes through the page's status-messages region, which isn't part of this standalone AJAX ReplaceCommand fragment. The form re-render did mark every répartition row with a subtle red outline, but with no visible explanation the modal just looked stuck. figli_compta_ledger_node_form_ajax_submit() now also emits a MessageCommand for each form error, mirroring the pattern already used for the success path's messenger() messages. Verified live: breaking a répartition sum and clicking Save now shows a proper error toast with the exact mismatch amount, the modal correctly stays open, and the node is confirmed unchanged in the database. --- .../figli_compta_ledger/figli_compta_ledger.module | 10 ++++++++++ 1 file changed, 10 insertions(+) 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;