Chase
Chase

Reputation: 9362

Disable validation checks on a single non mapped choice field

I have looked at a lot of the relevant questions for this and cant seem to find one that fits my needs. The answers that come closest solving my problem involve adding the choices to the choice list using pre bind events. The problem with this is I have no way of knowing what the choices are the user added.

On the front end I have javascript / jquery that add options to a choice field based on user input. To keep it simple if the user types in hello world into an input box and option then is set in the choice field with a value of hello-world.

The info that the user puts in will not be persisted to a mapped entity column it is only used for display purposes then destroyed. However I need the rest of the form validated.

Also this form is generated dynamically in the controller using:

$this->get('form.factory')->createNamedBuilder();

TLDR: I need to disable validation on a single choice field generated using a createNamedBuilder from the form factory

Upvotes: 0

Views: 92

Answers (1)

Jovan Perovic
Jovan Perovic

Reputation: 20193

Heve you tried something like this:

$req = $this->getRequest();

$submittedOptions = array();

if ( $req->isMethod("POST")){
    $submittedOptions = $req->request->get('name_of_the_choice_field');
}

$this->get('form.factory')->createNamedBuilder()
    ....
    ->add('name_of_the_choice_field', 'choice, array(... , 'choices' => $submittdOptions, ... )
    ....

Upvotes: 1

Related Questions