You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following custom matrix validation implemented through the following event through a module.
Event::on(
MatrixBlock::class,
Model::EVENT_AFTER_VALIDATE,
staticfunction (Event$e) {
$siteId = $e->sender->siteId;
/** @var MatrixBlock $block */$block = $e->sender;
$owner = $e->sender->owner;
// Only concerned about a specific siteif ($siteId !== 1) {
return;
}
// Only if an entry and not a draftif ((is_a($owner, Entry::class) && ElementHelper::isDraftOrRevision($owner)) || $owner->duplicateOf) {
return;
}
// Custom validation conditions related to matrix block condition...// Throw an error message if condition met$block->addError('links', 'Custom validation message');
}
);
I have noticed that while the saving of the entry is correctly returned with a validation error the "Custom validation message" is not shown below the matrix block, the entry itself is prevented from saving, but no specific message is shown which is a bit awkward.
I suspect that the logic for skipping a draft is causing the no validation message problem, but I kind of don't want a draft to be prevented as this would prevent any autosave being saved, really only when an entry needs to be saved for live purposes or committed as a revision.
I don't know if there's a way I can have the best of both worlds in this scenario, but thought I'd ask.
Steps to reproduce
Implement logic as above.
Create an entry with a matrix block that triggers the condition
Entry will be invalid, but no custom error message shown.
Expected behavior
Custom error message to be shown for the custom validation logic.
Actual behavior
No custom error message displayed, but the entry is marked as invalid.
Craft CMS version
3.9.13
PHP version
8.1
Operating system and version
No response
Database type and version
MySQL 8
Image driver and version
No response
Installed plugins and versions
N/A
The text was updated successfully, but these errors were encountered:
What happened?
Description
I have the following custom matrix validation implemented through the following event through a module.
I have noticed that while the saving of the entry is correctly returned with a validation error the "Custom validation message" is not shown below the matrix block, the entry itself is prevented from saving, but no specific message is shown which is a bit awkward.
I suspect that the logic for skipping a draft is causing the no validation message problem, but I kind of don't want a draft to be prevented as this would prevent any autosave being saved, really only when an entry needs to be saved for live purposes or committed as a revision.
I don't know if there's a way I can have the best of both worlds in this scenario, but thought I'd ask.
Steps to reproduce
Expected behavior
Custom error message to be shown for the custom validation logic.
Actual behavior
No custom error message displayed, but the entry is marked as invalid.
Craft CMS version
3.9.13
PHP version
8.1
Operating system and version
No response
Database type and version
MySQL 8
Image driver and version
No response
Installed plugins and versions
N/A
The text was updated successfully, but these errors were encountered: