php - Symfony3 form errors are not shown(just notNull/notBlank), the rest of them are working -
i try validate symfony3 form, use 2 constraints each entity field, (notblank , float). float constraint's error message shown correctly, notblank error messages shown whole form(global errors) not each separated filed. i've tried use notnull instead of notblank, didn't me.
bellow i've copy/pasted snippets of code.
class parameterstype extends abstracttype { /** * @param formbuilderinterface $builder * @param array $options */ public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('variable_sheer_header', numbertype::class, [ 'label' => 'parameters.variable_sheer_header', 'error_bubbling' => true , 'attr' => [ 'placeholder' => 'parameters.variable_sheer_header', "class" => 'form-control' ], ]) ->add('variable_sheer_hem', numbertype::class, [ 'label' => 'parameters.variable_sheer_hem', 'error_bubbling' => true , 'attr' => [ 'placeholder' => 'parameters.variable_sheer_hem', "class" => 'form-control' ], ]) ->add('variable_sheer_overlap', numbertype::class, [ 'label' => 'parameters.variable_sheer_overlap', 'error_bubbling' => true , 'attr' => [ 'placeholder' => 'parameters.variable_sheer_overlap', "class" => 'form-control' ], ]) ...
use doctrine\odm\mongodb\mapping\annotations mongodb; use symfony\component\validator\constraints assert; /** * @mongodb\embeddeddocument() */ class parametersembedded { /** * @var float * * @assert\type(type="float", message="parameters.field.not.float") * @assert\notblank(message="parameters.field.not.empty") * * @mongodb\field(type="float") */ protected $variablesheeroverlap; /** * @var float * * @assert\notnull(message="parameters.field.not.empty") * @assert\type(type="float", message="parameters.field.not.float") * * @mongodb\field(type="float") */ protected $variablesheerrod;
-#index.html.haml = form_start(form) .settings-form %p.title-form= 'user.parameters'|trans .row .col-xs-4 %h4.parameters-group-name='parameters.variable_sheer'|trans = form_row(form.variable_sheer_hem) = form_errors(form.variable_sheer_hem) = form_row(form.variable_sheer_overlap) = form_errors(form.variable_sheer_overlap) = form_row(form.variable_sheer_rod) = form_errors(form.variable_sheer_rod) = form_row(form.variable_sheer_header) = form_errors(form.variable_sheer_header) .col-xs-4 %h4.parameters-group-name='parameters.other'|trans = form_row(form.other_hem) = form_errors(form.other_hem) = form_row(form.other_overlap) = form_errors(form.other_overlap) = form_row(form.other_rod) = form_errors(form.other_rod) = form_row(form.other_header) = form_errors(form.other_header) .col-xs-4 %h4.parameters-group-name='parameters.shade'|trans = form_row(form.shade_add_hem_length) = form_errors(form.shade_add_hem_length) = form_row(form.shade_add_hem_width) = form_errors(form.shade_add_hem_width) = form_row(form.submit)ubmit) = form_end(form)
// controller public function profileparametersaction(request $request) { $form = $this->createform(parameterstype::class); $form->handlerequest($request); if ($form->isvalid()) { $this->getuser()->setparameters($form->getdata()); $this->getdm()->flush(); $this->addflash('success', 'user.profile.parameters.changed'); } return $this->render('appbundle:profile:parameters.html.haml', [ 'form' => $form->createview() ]); }
you suppose use required true attribute passed in form.
check here: http://symfony.com/doc/current/reference/forms/types/form.html#required
Comments
Post a Comment