Skip to content

[LiveComponent] Validation doesn't seem to work #2974

@javiereguiluz

Description

@javiereguiluz

Hi team!

I'm trying to validate a property of some LiveComponent that doesn't use a Symfony Form. I'm following this: https://symfony.com/bundles/ux-live-component/current/index.html#validation-without-a-form

My code is like this:

#[AsLiveComponent]
class MyComponent
{
    use DefaultActionTrait;
    use ValidatableComponentTrait;

    #[LiveProp(writable: true)]
    #[Assert\Choice(choices: ['foo', 'bar'])]
    public string $type;

    // ...
}

If I put this in my template, I expect to see an error, but I don't see anything. The LiveComponent renders normally, without validating the value of the $type property:

<twig:MyComponent type="aaaaa"/>

Also, on the Symfony Docs, I don't understand the followin:

Be sure to add the IsValid attribute/annotation to any property
where you want the object on that property to also be validated.

The docs doesn't show any example using that IsValid attribute and I'm not sure where to find it. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions