Vichuploaderbundle: The label appears twice

Created on 14 Jan 2015  路  14Comments  路  Source: dustin10/VichUploaderBundle

Hello

I use the bundled file form type, but I don't know why the label appears twice
I user bootstrap template {% extends "bootstrap_3_layout.html.twig" %}
sf 2.6

Html generate :

 <div class="form-group">
            <label class="control-label">Scan de la candidature</label>


            <div class="vich-file">
                <div class="form-group">
                    <label class="control-label" for="grh_carrierebundle_candidature_file_file">Scan de la candidature</label>
                    <input type="file" id="grh_carrierebundle_candidature_file_file" name="grh_carrierebundle_candidature[file][file]" />
                </div>
            </div>
        </div>  

My form type

->add('file', 'vich_file', array(
                    'label' => 'Scan de la candidature',
                    'required' => false ));

In twig

{{ form_row(form.file) }}

And entity

/**
     * @Assert\File(
     *     maxSize="9M"
     * )
     * @Vich\UploadableField(mapping="canditature_file", fileNameProperty="fileName")
     *
     * @var File $file
     */
    protected $file;

Thanks

Bug

Most helpful comment

Had same issue then added the theme as specified in the documentation (thanks @ahoulgrave ):

twig:
form_themes:
- bootstrap_3_layout.html.twig
- 'VichUploaderBundle:Form:fields.html.twig'

And that solved the issue.

All 14 comments

How about you remove label from html?
I think it because you render a label in Html while in form type you also state label.

Try to remove it with javascript.
This is what I have done for my case!

If I remove

 ->add('file', 'vich_file', array(
                    'label' => '',

it's the same effect

<div class="form-group">
                            <label class="control-label">File</label>    
        <div class="vich-file"><div class="form-group"><label class="control-label" for="grh_carrierebundle_candidature_file_file">File</label><input type="file"/>

Ok @mappedinn but then it's a bug ?

Thanks

Hi @jfsenechal, I change 'vich_file' to 'file' and it does not duplicate the label.

->add('file', 'file', array(
'label' => 'Upload File',

Saludos

I solved the problem by overriding the view of the field
and replace form_row by form_widget :

{% block vich_file_widget %}
    {% spaceless %}
        <div class="vich-file">
            {{ form_widget(form.file) }} {# here #}
...

Still this same issue.

A fix has been merged.

This is happening to me in 0.14.0.

Furthermore, I check the commit 02fa02d that closed this issue. It doesn't look like there is anything to do with "to fix label rendered twice dustin10/VichUploaderBundle#369".

Cheers

Hi @nachinius, the referenced commit was for another project, commit b379cd8 seems to fix this issue. However it wasn't backported, and I'm not sure if no upgrade instructions means we can just use dev-master in place of 0.14.0.

A workaround to only render the label once would be to set a label in your FormType as usual, but then set the label as false when rendering the row in your Twig template:

{{ form_row(form.externalCertificateFile, {label: false}) }}

I had the same problem and fixed it with @jfsenechal solution. Thanks!

Both workaround from @lushc and @jfsenechal worked. I preferred to use the @lushc this time. Thanks.

Had same issue then added the theme as specified in the documentation (thanks @ahoulgrave ):

twig:
form_themes:
- bootstrap_3_layout.html.twig
- 'VichUploaderBundle:Form:fields.html.twig'

And that solved the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benIT picture benIT  路  3Comments

petrjirasek picture petrjirasek  路  7Comments

NicolaPez picture NicolaPez  路  6Comments

jcg678 picture jcg678  路  6Comments

fleskalebas picture fleskalebas  路  6Comments