admin管理员组

文章数量:1391987

I am building the Symfony form with a CollectionType field. The application logic assumes that new items can be added. To be short in explanation what is done, I am providing the link from the official docs. Consider my setting is just the same. .html#javascript-with-stimulus

The actual problem is when I pass the prototype to stimulus controller like this:

<div {{stimulus_controller(‘url-manager’, {prototype: form_row(prototype)|e(‘html_attr’)})}}></div>

And then in controller creating new element, setting its innerHTML to this.prototypeValue, it is being inserted as text, not html element.

However, if I do pass the prototype without applying filter |e, all works fine.

Could anyone advise if this is due to some change not being reflected in the docs? Or maybe the stimulus_controller() helper function applies some additional filtering?

The helper function is the only difference of my implementation from the docs.

I am building the Symfony form with a CollectionType field. The application logic assumes that new items can be added. To be short in explanation what is done, I am providing the link from the official docs. Consider my setting is just the same. https://symfony/doc/current/form/form_collections.html#javascript-with-stimulus

The actual problem is when I pass the prototype to stimulus controller like this:

<div {{stimulus_controller(‘url-manager’, {prototype: form_row(prototype)|e(‘html_attr’)})}}></div>

And then in controller creating new element, setting its innerHTML to this.prototypeValue, it is being inserted as text, not html element.

However, if I do pass the prototype without applying filter |e, all works fine.

Could anyone advise if this is due to some change not being reflected in the docs? Or maybe the stimulus_controller() helper function applies some additional filtering?

The helper function is the only difference of my implementation from the docs.

Share Improve this question edited Mar 13 at 6:43 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Mar 12 at 21:41 MaxMax 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Actually I found in the docs, that stimulus_controller() helper function escapes all non-scalar values, thus it is better to declare values in a straight forward attribute style.

data-controller="url-manager"
data-url-manager-prototype-value="{{ form_row(prototype)|e('html_attr') }}"

本文标签: symfonyHow to pass prototype to Stimulus controllerStack Overflow