symfony form validation message for hidden field not shown -


my problem pretty simple, don't know solve it.

here situation :

in symfony2 (2.3.*) i've created form (documenttype.php + twig render template). file form included. there classic fields (text, choices) plus 1 file input. file input pretty particular, i'm using little hack custom element's render attributes.

here entitytype class :

class documenttype extends abstracttype {     public function buildform(formbuilderinterface $builder, array $options)     {         $builder             ->add(                 'documentname',                 'text',                 array(                     'label' => 'nom du document'                 )             )             ->add(                 'documentversioncustom',                 'text',                 array(                     'required' => false,                     'label' => 'version personnalisée'                 )             )             ->add(                 'documentstatus',                 'choice',                 array(                     'choices' => document::getstatuschoices(),                     'attr' => array(                         'class' => 'select2',                     ),                     'label' => 'etat'                 )             )             ->add(                 'file',                 'file',                 array(                     'mapped' => false,                     'attr' => array(                         'class' => 'hidden'                     ),                     'label' => 'fichier',                     'required' => true                 )             );     }      public function setdefaultoptions(optionsresolverinterface $resolver)     {         [...]     }      public function getname()     {         [...]     } } 

here twig template (partial):

             <div class="row">                 {{ form_errors(form) }}                 <legend class="span12">informations du fichier</legend>                  {{ form_label(form.documentname,'nom du fichier',{'label_attr':{'class':'span4' }}) }}                 {{ form_errors(form.documentname) }}                 {{ form_widget(form.documentname,{'attr':{'class':'span8' }}) }}                  {{ form_label(form.documentversioncustom,'version personnalisée',{'label_attr':{'class':'span4' }}) }}                 {{ form_errors(form.documentversioncustom) }}                 {{ form_widget(form.documentversioncustom,{'attr':{'class':'span8' }}) }}                  {{ form_label(form.documentstatus,'État',{'label_attr':{'class':'span4' }}) }}                 {{ form_errors(form.documentstatus) }}                 <div class="row">                     {{ form_widget(form.documentstatus,{'attr':{'class':'span8 select2' }}) }}                 </div>                  <div class="row">                     {#{{ form_label(form.file,'fichier',{'label_attr':{'class':'span4' }}) }}#}                     {{ form_errors(form.file) }}                     {{ form_widget(form.file,{'attr': {'style': 'display:none;' },'id' : 'browsefile' }) }}                     <label for="browsefile" class="span4">fichier</label>                      <div class="row">                         <div class="input-append span8">                             <input type="text" name="subfile" id="subfile" onclick="$('#browsefile').click();">                             <a class="btn btn-success" onclick="$('#browsefile').click();">parcourir</a>                         </div>                     </div>                 </div>                 <div class="row">                 </div>                 {#<div class="row">#}                     <input id="fileformsubmitbutton" type="submit" value="ajouter" class="btn btn-primary span3"/>                     <span class="span6">&nbsp;</span>                     <input id="fileformcancelbutton" type="button" value="annuler" class="btn span3"/>                 {#</div>#}             </div> 

my little hack file input hide standard input and, javascript, redirecting events (click, focus) styled element hidden 1 ( #subfile => form_widget(form.file) ).

everything works fine, problem file input. when submiting form, validation messages correctly shown required standard inputs, file input (that required too), message shown in bottom left hand corner of browser (the way see « symfony popup tooltip » keep browser (firefox in case) not in fullscreen mode.

my question : there way specifiy in symfony formtype or anywhere else « attach » error message specific component ?

thank you

it's possible custom constraint. in validator class, use

$this->context     ->addviolationat('lastname', $constraint->message, array('%string%' => $value)); 

but honestly, if file input wouldn't have error. use input type file form class, or without it, not half half.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -