Cms: Confusing error message after save if matrix field with minimum block count has no blocks

Created on 2 Jun 2020  ·  7Comments  ·  Source: craftcms/cms

Description

If a matrix field has fewer than the required number of blocks at the time of save, the save errors and the field is padded with new blocks to meet the minimum.

So far so good! But the error message that comes with it is potentially confusing. The message is "[field name] should contain at least [minimum] blocks." Because of the automatic-padding behavior (which again I would not want to see go away, it's great) the user is left looking at a field with the correct number of blocks and a message apparently saying 'the entry could not be saved because this field needs at least as many blocks as it in fact has.'

Steps to reproduce

  1. Create a matrix field with a minimum block count
  2. Create a section
  3. Add the field to the section
  4. Create an entry in the section
  5. In the entry, delete a block from the matrix field
  6. Save the entry

Additional info

This is Chrome 83

  • Craft version: 3.4.20
  • PHP version: 7.2.24
  • Database driver & version: MySQL 5.7.29
  • Plugins & versions:
Advanced Url Field 1.0.0
Amazon S3 1.2.8
Analytics 4.0.10
Asset Rev 6.0.2
Control Panel Nav 3.0.12
Cookies 1.1.12
CP Field Inspect 1.1.3
Element Map 1.2.1
Embedded Assets 2.2.4
Entry Instructions 1.0.7
Environment Label 3.2.0
Expanded Singles 1.1.2
Field Manager 2.1.6
Flat Categories 2.0.0
Image Resizer 2.0.8
Inventory 2.1.0
Matrix Colors 2.0.1
Password Protect 1.0.0
Redactor 2.6.1
Redirect plugin for Craft 3 1.0.23
SuperSort 3.0.1
Super Table 2.4.9
Twig Perversion 2.1.0
Video Embed 1.2.1

All 7 comments

I’m not able to reproduce that – the validation error begins with the field name, e.g. “My Field should contain at least 2 blocks”. Have you provided a custom static translation for your field name that replaces it with an empty string, or something like that?

🤦 I didn't account for Markdown's handling of angle brackets

"\ should contain at least \ blocks"

Confusing because, thanks to the auto-padding, it's possible to not see the message until the reported requirement is already satisfied. Might complicate the erroring setup's conditions but something like "\ should contain at least \ blocks. You may now resave.", or "\ should contain at least \ blocks. The necessary blocks have been added automatically but are emtpy", etc, would resolve the confusion

Ahh, gotcha. I just tweaked the behavior for the next release, so additional blocks will no longer be created if there is a validation error on the field.

That works, thanks!

Lowest possible priority follow up question, feel free to never respond: after looking at the change (and I admit without reading through the whole file) and seeing all the many contexts where createDefaultBlocks will be false, I'd be interested to hear if there's some common context where it will be true.

It is true whenever Min Blocks is set, and the field only has one block type (so we can safely assume which type of blocks to auto-create), and (as of the next release) there are no validation errors on the field.

Craft 3.4.23 is out now with this change.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings