0

I would like to include JavaScript inside a form widget in Symfony2, but quotes are escaped inside the JavaScript command, see:

{{ form_widget(form.sdf, 
    { 'attr': { 'value': "document.MSketch.getMol('sdf');" } } 
) }}

and the result I get:

<input type="hidden" id="form_sdf" name="form[sdf]" required="required" value="document.MSketch.getMol(&#039;sdf&#039;);" />

I have read this topic : Twig and autoescaping But autoescape false is not working when using it like this:

{% autoescape false %}
{{ form_widget(form.sdf, 
    { 'attr': { 'value': "document.MSketch.getMol('sdf');" } } 
) }}
{% endautoescape %}

How to have quotes?

EDIT: Using raw filter isn't helping:

{% set cmd = 'document.MSketch.getMol("sdf");' %}
{{ form_widget(form.sdf, { 'attr': { 'value': cmd|raw } } ) }}

But raw filter is working outside of the form_widget, so where is the problem?

1 Answer 1

1

Have you tried to simply escape quotes? \' or \"

Sign up to request clarification or add additional context in comments.

1 Comment

Simple escaping is not working. As a temporary fix, i put my JavaScript inside my submit button onclick attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.