-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The choice "464" does not exist or is not unique #8
Comments
Which Type (Choice/Entity/Document) are you using ? |
Hi, I use an Entity. In my form : $builder->add('arriveIn', ExtensibleEntityType::class, array(
'choices' => array(), // Prevent default EntityType behavior (load all entities)
'label' => 'Service',
'route' => 'ref_service_search_all',
'class' => 'AppBundle:Service',
'choice_label' => 'name',
)); The subscriber (Alsatian\FormBundle\Form\Extensions\ExtensibleSubscriber) do his job on PRE_SET_DATA and PRE_SUBMIT : // [...]
$form->add($childName, $type['originalType'], $options);
if ( $childName == 'arriveIn' ) { // For testing choices are populated - it's OK.
dump($form->get($childName)->getConfig()->getOptions()['choices']);
} Note : I have 5 fields in the form with the ExtensibleEntityType. But I don't think it's the problem. |
When I dig in Form mechanism, I found this :
|
First of all, try to remove It is already set here Where is your exception thrown ? if yes : Is 674 the id of a submitted AppBundle:Service entity ? |
Both of them. I tested to inject a Service entity mapped in arriveIn field. I pass through the subscriber, it does its job but nothing... no option tag... it's like the $form in subscriber it's ont the same as the $form create in controller. Otherwhise, the exception is thrown in transformer on PRESUBMIT. Logic, because the list is empty. |
Did you try to remove your |
Yes |
I will try to do the same thing again in a clean symfony version. For information I am under symfony 2.8.*. I will make you a return. |
I wrote this bundle using the 2.8 version ... My subscriber works with a priority of -50 : May be you have some other listener acting after my PRE_SUBMIT event ? |
Hi, I tested your bundle on a fresh Symfony 2.8.18... and I have the same behavior. Maybe I missed something... I started by the view :
The Form : class MyFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('service', ExtensibleEntityType::class, array(
'choice_label'=>'name',
'class' => 'AppBundle\Entity\Service',
'placeholder' => 'Veuillez sélectionner un service'
));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\MyEntity'
));
}
public function getBlockPrefix()
{
return 'my_form';
}
public function getName()
{
return $this->getBlockPrefix();
}
} The controller : public function indexAction(Request $request)
{
$myEntity = new MyEntity();
$form = $this->createForm(MyFormType::class, $myEntity);
$form->handleRequest($request);
if ( $form->isSubmitted() && $form->isValid() ) {
$myEntity = $form->getData();
}
return $this->render('AppBundle:default:index.html.twig', array(
'form' => $form->createView()
));
} MyEntity entity : class MyEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var integer
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Service")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotNull()
*
* @var \AppBUndle\Entity\Service
*/
private $service;
} Service entity : class Service
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var integer
*/
private $id;
/**
* @ORM\Column(type="string", nullable=false)
* @Assert\NotNull()
*
* @var string
*/
private $name;
} |
Et si on parlait français, ce serait peut-être plus simple ? En fait je sais pas trop d'où vient ton problème. J'ai vu que plusieurs commits ont changé ce qui touche à l'EntityType que je surcharge ... Je n'utilise plus du tout symfony depuis plusieurs mois et je ne pas si mon bundle marche encore sur mon application, je vais m'y replonger pour y répondre, mais j'ai pas trop le temps avant plusieurs jours. Ce que tu peux faire pour débuguer :
Voilà ce que tu peux faire en attendant ... Je teste dès que j'ai le temps |
J'ai fais les tests sur tous les événements, et la modification est bien prise en compte pratout. Je crois que j'ai levé un loup, le noeud du problème est que le transformer dans son reverse_transform fait appel au loader foreach ($values as $i => $givenValue) {
if (array_key_exists($givenValue, $this->choices)) {
$choices[$i] = $this->choices[$givenValue];
}
} Le Ce qui n'est pas normal, c'est qu'on la modifie cette liste via |
J'ai avancé, Lorsque j'édite une entité qui a un service de renseigné (entité Service mappé sur le champ service), le PRE_SET_DATA fonctionne si et seulement si je définie un buildView() de mon formulaire MyFormType. Par contre, lorsque je soumet le formulaire, toujours rien. |
Bizarre, chez moi j'ai tout mis à jour, (sur symfony 3.2), j'ai tout re-testé et tout fonctionne toujours très bien. Peut-tu me faire un genre de fork minimal qui reproduit le bug ? |
Je vais te mettre dans un dépôt le symfony 2.8 et ton bundle. |
I have the same issue did you resolved above issue, if yes then can you explain? |
I could not reproduce the same issue. It is till open. |
Hi,
I do not understand why but I still have the following error: "The choice "464" does not exist or is not unique". By doing tests, I get into the "subscriber", the "choices" array is populated but the error is still there.
In the profiler, I have the following information after submission :
Can you help me ?
The text was updated successfully, but these errors were encountered: