Show the répartition validation error message instead of failing silently
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user