silverstripe / silverstripe-elemental

Create pages in Silverstripe CMS using content blocks
http://dna.co.nz
BSD 3-Clause "New" or "Revised" License
109 stars 115 forks source link

Only a single RequiredFields validation message shows at a time #1187

Closed emteknetnz closed 3 months ago

emteknetnz commented 4 months ago

Split off from https://github.com/silverstripe/silverstripe-elemental/pull/1178#pullrequestreview-2041868677

Elemental inline-editable blocks when you save the page, only one required field validation message appears at a time.

So if I don't enter any data I only get told about the title, then I add a title and I'm told about the image, then I add an image and I'm told about the page.

The HTTP response does have all three validation errors at the same time

Acceptance criteria

emteknetnz commented 3 months ago

I can't replicate, seems like it works correctly on 5.x-dev

Using the following code for my content block

app/src/MyBlock.php

<?php

use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Assets\Image;

class MyBlock extends BaseElement
{
    private static $db = [
        'MyField' => 'Varchar',
        'MyOtherField' => 'Varchar',
    ];

    private static $has_one = [
        'MyImage' => Image::class,
        'MyOtherImage' => Image::class,
    ];

    private static $table_name = 'MyBlock';

    private static $singular_name = 'My Block';

    private static $plural_name = 'My Blocks';

    private static $description = 'This is my block';

    private static $icon = 'font-icon-block-content';

    public function getType()
    {
        return 'My Block';
    }

    public function getCMSCompositeValidator(): CompositeValidator
    {
        return CompositeValidator::create([new RequiredFields([
            'MyField',
            'MyOtherField',
            'MyImage',
            'MyOtherImage'
        ])]);
    }
}

app/src/MyModelAdmin.php

<?php

use SilverStripe\Admin\ModelAdmin;

class MyBlockAdmin extends ModelAdmin
{
    private static $url_segment = 'MyBlockAdmin';

    private static $menu_title = 'My block admin';

    private static $managed_models = [
        MyBlock::class,
    ];
}

When I page save I get this

image

When I edit from a ModelAdmin I get this

image

When I inline save I get this, the reason only the textfields have validation message is because there's client side validation that happens before sending it to the server, though it's not active on the upload fields

image

When I fill in the textfields with values and submit, I get back multiple validation warnings

image

maxime-rainville commented 3 months ago

@GuySartorelli wants to have a second look.

GuySartorelli commented 3 months ago

The problem I was seeing only happens if Title is a required field. That's covered by https://github.com/silverstripe/silverstripe-elemental/issues/1179 so I'm happy to call this a non-issue.