Reputation: 1
I have a problem with symfony validation. After adding NotBlank or Length to the entity validation displays a standard message for missing values(default message NotBlank). Regardless of whether the field has been filled or not.
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\OneToOne;
use Symfony\Component\Validator\Constraints as Assert;
class Employee
{
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=30)
* @Assert\NotBlank()
* @Assert\Length(min="3")
*/
private $name;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add("name", TextType::class, ['label'=>"Imie"])
->add("submit", SubmitType::class, ["label"=>"Licytuj"]);
}
/**
* @param OptionsResolver $resolver
*/
public function configureOprions(OptionsResolver $resolver)
{
$resolver
->setDefaults
(
[
"data_class"=>Employee::class,
'attr'=>array('novalidate'=>'novalidate')
]
);
}
Upvotes: 0
Views: 765
Reputation: 488
I couldn't find any issue with the code you posted. Most probably the issue will be on your controller code. Most probably you are loading a validated form into the view in the form load itself. For the better understanding please add your controller and view you are using. Sorry for writing this in the answer section.
Upvotes: 0
Reputation: 2812
You have a naming issue. Change method name to override configureOptions
method.
configureOprions
=> configureOptions
Upvotes: 1