symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony
https://ux.symfony.com/
MIT License
858 stars 315 forks source link

Add ability to add inputProps in component inside eventListener #2277

Closed tito10047 closed 1 month ago

tito10047 commented 1 month ago
Q A
Bug fix? no
New feature? yes
Issues Fix #2276
License MIT

Add ability to modity InputProps inside EventListener

#[AsEventListener(priority: 100)]
class UxIconListener
{
    public function __invoke(PreCreateForRenderEvent $event): void
    {
        if ('ux:icon' !== strtolower($event->getName())) {
            return;
        }
        $attributes = $event->getInputProps();

        if ($attributes['name']!=="my-global-icon"){
            return;
        }

        $attributes["class"] = "icon view";
        $attributes["title"]= "this item is public";

        $event->setInputProps($attributes);

    }
}
smnandre commented 1 month ago

This event is not designed for this usage, but to return HTML and bypass the system.

You can achieve similar goal by: