adding constraint to fields

This commit is contained in:
Julien Fastré 2016-12-20 22:24:58 +01:00
parent e5c7a4a342
commit 0e848e0829
2 changed files with 15 additions and 1 deletions

View File

@ -13,6 +13,8 @@ use Chill\MainBundle\Export\FormatterInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Render a list of peoples
@ -59,7 +61,16 @@ class ListPerson implements ListInterface
'multiple' => true,
'expanded' => true,
'choices' => array_combine($this->fields, $this->fields),
'label' => 'Fields to include in export'
'label' => 'Fields to include in export',
'constraints' => [new Callback(array(
'callback' => function($selected, ExecutionContextInterface $context) {
if (count($selected) === 0) {
$context->buildViolation('You must select at least one element')
->atPath('fields')
->addViolation();
}
}
))]
));
}

View File

@ -12,3 +12,6 @@
'Closing date can not be null': 'La date de fermeture ne peut être nulle'
The date of closing is before the date of opening: La période de fermeture est après la période d'ouverture
The birthdate must be before %date%: La date de naissance doit être avant le %date%
#export list
You must select at least one element: Vous devez sélectionner au moins un élément