8000 [Form] Customize an Individual field with camelCase name · Issue #3195 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Form] Customize an Individual field with camelCase name #3195

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

Closed
tiois opened this issue Jan 26, 2012 · 10 comments
Closed

[Form] Customize an Individual field with camelCase name #3195

tiois opened this issue Jan 26, 2012 · 10 comments
Milestone

Comments

@tiois
Copy link
tiois commented Jan 26, 2012

I followed the documentation here : http://symfony.com/doc/2.0/cookbook/form/form_customization.html#how-to-customize-an-individual-field , it's working for all the fields I wanted to modify the display, except for one field that is named with camelCase.

The field :

<tr>
    <th>
        <label for="adtype_imageFile">Image</label> :    
    </th>
    <td>
        <input type="file" id="adtype_imageFile" name="adtype[imageFile]" />
    </td>
</tr>

The overrided block for this field :

{% block _adtype_imageFile_row %}
    <tr>
        <th{% if form_errors(form) %} class="error"{% endif %}>
            * {{ form_label(form, label|default(null)) }}
        </th>
        <td>
            {{ form_widget(form) }}
            {% if errors|length > 0 %}
                <div class="error">
                    {{ form_errors(form) }}
                </div>
            {% endif %}
        </td>
    </tr>
{% endblock %}

In the same view, I defined individual blocks and it's working fine, except for this one. Working fields are the ones named in lowercase.

Exemple of a working field :

{% block _adtype_translation_html_row %}
    <tr>
        <th{% if form_errors(form) %} class="error"{% endif %}>
            * {{ form_label(form, label|default(null)) }}
        </th>
        <td>
            {{ form_widget(form) }}
            {% if errors|length > 0 %}
                <div class="error">
                    {{ form_errors(form) }}
                </div>
            {% endif %}
        </td>
    </tr>
{% endblock %}

Am I doing something wrong?

Thanks!

@tiois
Copy link
Author
tiois commented Jan 27, 2012

Just to clarify, the bug is that this block is never rendered.

@webmozart
Copy link
Contributor

Does it work if you name the block "_adtype_image_file_row"?

@tiois
Copy link
Author
tiois commented Jan 30, 2012

No, I tried "_adtype_image_file_row" as well as "_adtype_imagefile_row", but no luck.

@tiois
Copy link
Author
tiois commented Feb 1, 2012

Any update on this issue?

@webmozart
Copy link
Contributor

Not yet, I need to look into this. If you can dive into the code to find out what the generated block name is, I'd be very grateful.

@tiois
Copy link
Author
tiois commented Feb 1, 2012

Alright, I'll take a look!

@vicb
Copy link
Contributor
vicb commented Feb 1, 2012

I have only looked at this quickly but you might want to look at the folowing:

{% block _adtype_imageFile_row %} has been called while rendering the adtype_imageFile widget.

Calling is {{ form_widget(form) }} inside your block is like a recursive call so it will not render the parent sections but start over from the current section see the form extension.

More details in the corresponding PR.

Without this PR your template would have caused an infinite recursion. See this for an example of what the PR made possible.

If this turns to be the root cause could you please:

  • check if this is documented
  • if not check if there is a defect pending in the doc
  • if not create an issue for me to document this on sf docs

@tiois
Copy link
Author
tiois commented Feb 2, 2012

Sorry guys, I found that the problem is that this field is rendered by a template included in my form... :

{% include 'ProjectCoreBundle:Core:image_field.html.twig' with {
    'fieldName': 'image',
    'required': true,
    'translatable': true
} %}

But this brings me to another question, is it possible to override a collection label ?

For example, I would like to do :

{% block user_userroles_$$name$$_label %}
{% spaceless %}
    {% set attr = attr|merge({'for': id}) %}
    {{ block('generic_label') }}
{% endspaceless %}
{% endblock user_userroles_$$name$$_label %}

But I get :

Unexpected character "$" in ProjectUserBundle:User:edit_fields.html.twig at line 34

@vicb
Copy link
Contributor
vicb commented Feb 3, 2012

This is not an issue but a support request now so please read the doc, ask your question on the user list and if this turns to be an issue come back here.

  • Please close this issue,
  • Do not forget to specify the Sf2 version you're using when asking questions on the ML,
  • You should also consider contributing the doc once you've got a response (if it is not there)

(i don't have your reply on top of my head, the proto rendering has been changed by @marcw some time ago)

@tiois
Copy link
Author
tiois commented Feb 3, 2012

Thanks for your support guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0