Description
Hi,
I'm trying to implement expanded ChoiceCaptchaType (expanded ChoiceType where choices and values are loaded dynamically each time and only the choice matched prev. saved choice passes the current ChoiceType::PRE_SUBMIT event ), and now i understand that's not so easy. (Thanks to no documentation about choice_loader
[requested])
Now i'm trying to implement exclusively choice_loader
approach without any other event listeners or transformers and in my opinion using only choice_loader
(and parent PRE_SUBMIT
event in the parent ChoiceType
of course) will be enough. The opinion based on choice_loader
self name.
My approach was to configure choice_loader
and unset choice_list_view
in attributes to load new choices from loader and totally rebuild the view.
And everything is great except one thing in the code bellow.
// Symfony\Component\Form\Extension\Core\Type\ChoiceType:182
/** @var ChoiceListInterface $choiceList */
$choiceList = $form->getConfig()->getAttribute('choice_list');
/** @var ChoiceListView $choiceListView */
$choiceListView = $form->getConfig()->hasAttribute('choice_list_view')
? $form->getConfig()->getAttribute('choice_list_view')
: $this->createChoiceListView($choiceList, $options);
only the $choiceListView
will be constructed (in my ideal case i need this reconstruction on each request) each time if no choice_list_view
exists, but at the same time choice_list
does not have the same behaviour. The prev. built choice_list
will be used, which was built at:
// Symfony\Component\Form\Extension\Core\Type\ChoiceType:55
$choiceList = $this->createChoiceList($options);
$builder->setAttribute('choice_list', $choiceList);
What do you think about this little fix (especially for me :) it will be great)?
In that case we do not need to create our CustomChoiceList
.
// Symfony\Component\Form\Extension\Core\Type\ChoiceType:182
/** @var ChoiceListInterface $choiceList */
$choiceList = $form->getConfig()->hasAttribute('choice_list')
? $form->getConfig()->getAttribute('choice_list')
: $this->createChoiceList($options);
Obviously this issue was about "How to change choices on the SUBMIT event using choice_loader
".