0

I try something like that - Validating dynamically loaded choices in Symfony 2

but this when we get submited form check possible values - in my sitation any is correct.

i add modification to allow any value - like here

$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
        $data = $event->getData();
        $event->getForm()->add('tags', 'tag', [
            'label'   => 'Sub Choice',
            'choices' => $data['tags'],
            'mapped'=>false,
            'required'=>false,
            'multiple'=>true,
        ]);
    });

but it not work - how to make it usable ?

tag is my input extens of choice (for js ajax chosen)

aynber
  • 22,380
  • 8
  • 50
  • 63
Developer
  • 2,731
  • 2
  • 41
  • 71
  • Please add more info – Alexandru Furculita Jan 30 '15 at 21:46
  • More info, i create input based on choice and create chosen http://harvesthq.github.io/chosen/options.html user can put any word in this input like text. But have suggest last used. So i need change validation. Id default symfony check request option with choices if it not exist it create error - bad value. This is my try to remove but not work – Developer Jan 31 '15 at 07:29

1 Answers1

0

ok i found problem. This example is ok but we need array_flip

here is working version

 $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
        $data = $event->getData();
        if(is_array($data['tags']))$data=array_flip($data['tags']);
        else $data = array();
        $event->getForm()->add('tags', 'tag', [
            'label'   => 'Sub Choice',
            'choices' => $data,
            'mapped'=>false,
            'required'=>false,
            'multiple'=>true,
        ]);
    });
Developer
  • 2,731
  • 2
  • 41
  • 71