silverstripe/silverstripe-elemental

Only a single RequiredFields validation message shows at a time

Closed this issue · 3 comments

Split off from #1178 (review)

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

  • When an elemental block contains multiple form validator errors, all errors are shown in the elemental form.

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

@GuySartorelli wants to have a second look.

The problem I was seeing only happens if Title is a required field. That's covered by #1179 so I'm happy to call this a non-issue.