0

Is it possible to render an input field without id? I would like to disable it in the twig file.

I want that because I have a error "non-unique id" in the chrome console.

I have conducted research using the Symfony's documentation and I have found something that should work: "Customizing Form Output all in a Single File with Twig"

The block I want to replace is

 {%- block widget_attributes -%}

This block is inside of the form_div_layout.twig.html

I put this inside of my_form.twig.html {% form_theme form _self %}

{% block form_row %}
    {%- block widget_attributes -%}
     id="{{ id }}" name="{{ full_name }}"
      {%- if disabled %} disabled="disabled"{% endif -%}
      {%- if required %} required="required"{% endif -%}
      {%- for attrname, attrvalue in attr -%}
          {{- " " -}}
          {%- if attrname in ['placeholder', 'title'] -%}
              {{- attrname }}="{{ translation_domain is same as(false) ? attrvalue : attrvalue|trans({}, translation_domain) }}"
          {%- elseif attrvalue is same as(true) -%}
             {{- attrname }}="{{ attrname }}"
          {%- elseif attrvalue is not same as(false) -%}
              {{- attrname }}="{{ attrvalue }}"
          {%- endif -%}
      {%- endfor -%}
  {%- endblock widget_attributes -%}
{% endblock form_row %}


{{ form_start(form) }}

......

And I get the error:

"Variable "full_name" does not exist. "

I don't want to edit the form_div_layout.html.twig

juanma_
  • 11
  • 5

1 Answers1

0

I did it!

For now, I think I found the solution

{% form_theme form _self %}
{% block form_row %}
    {% block input_widget %}
        {% set id = random() %} {# Random number for the id #}
        {{ block('form_widget') }}
    {% endblock input_widget %}
{% endblock form_row %}

{{ form_row(form.my_form) }}

This is not the final solution because I want the "id" not to show in the input form.

juanma_
  • 11
  • 5