From within a form, I have added a link which open a modal form in which I can edit a Paragraph. Here is the code for this link:
$form['my_modal_edit_form'] = [
'title' => $this->t('Edit'),
'url' => $this->ensureDestination($url),
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'height' => '99%',
'width' => '95%',
]),
]
];
This is working fine except when I have added a constraint on the Paragraph being edited:
When I wrongly encode this modal form to fire the constraint, the constraint error message will not be displayed in the modal form but in a "new" form which is not modal (I mean the same form but not modal).
This could lead to a data loose in the following scenario:
1-Change a field value of field AAA in the "original" form
2-Open the modal form to edit the paragraph
3-Wrongly encode it to fire the constraint
4-A new Paragraph Edit form is displayed (the modal is removed). This means that the "original" form is "replaced" thus we lost the encoding of the AAA field.
My question is: How can I make sure that the modal is not replaced by the "not modal" same form when an error is displayed
Note: It looks like some constraints are working fine:
Working fine: A required "text" field will display some kind of popup near the missing value in the modal form
Not working: But a required "file" field will go into the problem. (A file field that you set as required in the Field UI)