Skip to content
Snippets Groups Projects
Commit 3e62c15c authored by Maxime Veber's avatar Maxime Veber
Browse files

Update heahdude example

Now working, type error catching was missing.
parent 34eea023
Branches master
No related tags found
No related merge requests found
......@@ -47,34 +47,24 @@ class TestHeahdudeController extends AbstractController
$forms = iterator_to_array($forms);
try {
$viewData = new ParentModel($forms['content']->getData(), new ColorVo($forms['color']->getData()));
} catch (InvalidColorException $error) {
// What to do here ?!
// This does not work
// $forms['colorCondition']->setData(false);
// Even if it would, the error path is wrong!
}
// Catching all potential exception will result in null data in the form, which is ok.
} catch (InvalidColorException $error) {} catch (\TypeError $error) {}
}
})
->add('color', ColorType::class, [
// Those constraints will act on form data, not view data. The form data remains not altered if there
// is an exception while processing the datamapper.
'constraints' => [
new Type(['type' => 'string']),
new Callback(['callback' => ColorVo::class . '::validateColor'])
]
])
->add('content', TextType::class)
->add('colorCondition', CheckboxType::class, [
'label' => 'Accept color',
'required' => false,
'mapped' => false,
'empty_data' => true,
'constraints' => new IsTrue(['message' => 'Wrong color input'])
])
->getForm();
$form->submit(['color' => 10, 'content' => 'foobar']);
dump($form->getErrors(true, true));
return $this->json([
'message' => 'Welcome to your new controller!',
'path' => 'src/Controller/TestVoFormController.php',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment