-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
PHP functions to add Stimulus JS attributes #737
Comments
Any news on that? @weaverryan @tgalopin |
Hi! I've transferred the issue. Actually, it should be WebpackEncoreBundle... because that holds the Stimulus functions. But they are likely to move to a new bundle soon... so I've moved it here, which is a closer spot than before :). I like this idea! The 2nd version probably makes the most sense. I suppose we could also allow a You CAN already add targets and controllers via your Twig template. But, tbh, it's a bit ugly. |
@weaverryan Thanks for the feedback. Indeed, it's ugly, especially when you already have some attributes on a widget or you want to render a My team and I currently mixing the assignment of Another thing to evaluate: |
Thank you for this issue. |
Nope |
Thank you for this issue. |
Still nope |
Would you like to work on this feature? |
I could try 😅 We just need to decide which way we would like to go (see first post) |
I think the 2nd proposal is better, so i guess something like this $builder->add('country', CountryType::class, [
// 'attr' => [ ?
'stimulus_controller' => 'controllerName' ,
'stimulus_target' => ['path/to/controller' => 'targetName'],
'stimulus_action' => ['controllerName' => 'bar'],
// ],
]); I think user should have the choice to set them on attr, widget_attr, or row_attr.. this, with some form of callable support, would allow to set it to every choice item with a nice DX. And regarding syntax, i think we should handle different things.. Controller // controller names in path
'stimulus_controller' => 'foo/barBar',
// controller names in identifier syntax
'stimulus_controller' => 'foo--bar-baz',
// multiple controllers
'stimulus_controller' => ['foo', 'other'],
// controller with values ?
'stimulus_controller' => ['foo' => ['bar' => 'Bar?', 'baz' => 'Baz!'], 'bar'], Regarding values, a callable could be very usefull, and allow setting values dynamically depending of form data. Target // target per controller
'stimulus_target' => ['controllerName' => 'targetName'],
// multiple targets
'stimulus_target' => ['controllerName' => 'targetName', 'otherController' => 'otherTargetName'], Action // stimulus syntax
'stimulus_action' => 'click->clipboard#copy',
// action per controller (default event -> action)
'stimulus_action' => ['controllerName' => 'copy'],
// action per controller (event -> action)
'stimulus_action' => ['controllerName' => ['click' => 'copy']],
// action per controller with values
'stimulus_action' => ['controllerName' => ['click' => 'copy']],
// action with parameters ?? Same things for stimulus_outlets & stimulus_classes ? |
@smnandre What do you think about: 'stimulus_controller' => [
'controllerName' => [
'values' => [
'param1' => 'value1'
],
'classes' => [
'loading' => 'spinner'
],
'targets' => [
'other' => '.target'
]
]
] Syntax for targets: 'stimulus_target' => ['controllerName' => 'targetName'],
'stimulus_target' => ['controllerName' => 'targetName1 targetName2'],
'stimulus_target' => ['controllerName' => ['targetName1', 'targetName2']],
'stimulus_target' => ['controllerName' => 'targetName', 'otherController' => 'otherTargetName'], Syntax for actions: 'stimulus_action' => 'eventName->controllerName#actionName',
'stimulus_action' => ['controllerName' => 'actionName'],
'stimulus_action' => ['controllerName' => ['eventName' => 'actionName']],
'stimulus_action' => ['controllerName' => ['eventName' => ['actionName' => ['param1' => 'value1']]]] |
DX
Like very much all your examples except this one
Let's say "maybe later" and keep the door open? Ok for you ? What about adding this one too ? 'stimulus_controller' => 'controllerName', DTO ?Do we want only array_like structures ? What about some DTO ? Using a new kind of StimulusAttributes (we'll see later how to connect/generize it) but with no hard dependency to Twig to ease manipulation / serialization / etc.. and probably some restrictions on the keys :) Stimulus::controller('boo/bar', .. ...)
->action(...)
->action(...)
->target(...)
... @Kocal has still optimization things in its pocket if i'm not wrong.. and i have two or three things i'd like to suggest in to improve DX (& performances too)... ConfigOther question: should we add this on all fields ? Inside attr ? Because i don't know if we should add 5 or 6 PRFeel free to poke me on Slack, or publish in DRAFT here if you want to iterate over your PR even at start, and have some ongoing review :) |
This is basically the same like in doc for the StimulusBundle
This case is already handled 👍
|
Arrays are usually a pain to deal with, and more in this case when you won't be able to use PHPDoc on them. It's like the Twig function Using a new kind of |
@Kocal Can you show me an example or some dummy code how it should work? |
Let's continue on the PR then :) |
It would be nice to have functions or options to add Stimulus attributes on form widgets.
Something like
or
Same goes for
stimulus_action
andstimulus_controller
The text was updated successfully, but these errors were encountered: