Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
emteknetnz opened this issue May 7, 2024 · 3 comments
Closed

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

emteknetnz opened this issue May 7, 2024 · 3 comments

Comments

@emteknetnz
Copy link
Member

emteknetnz commented May 7, 2024

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.
@emteknetnz emteknetnz transferred this issue from silverstripe/silverstripe-admin May 7, 2024
@emteknetnz emteknetnz self-assigned this May 15, 2024
@emteknetnz
Copy link
Member Author

emteknetnz commented May 15, 2024

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
Copy link
Contributor

@GuySartorelli wants to have a second look.

@GuySartorelli
Copy link
Member

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.

@GuySartorelli GuySartorelli closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants