Commit
…choices are submitted
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,14 @@ class CheckboxType extends AbstractType | |
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder | ||
->addViewTransformer(new BooleanToStringTransformer($options['value'])) | ||
; | ||
// Unlike in other types, where the data is NULL by default, it | ||
// needs to be a Boolean here. setData(null) is not acceptable | ||
// for checkboxes and radio buttons (unless a custom model | ||
// transformer handles this case). | ||
// We cannot solve this case via overriding the "data" option, because | ||
// doing so also calls setDataLocked(true). | ||
$builder->setData(isset($options['data']) ? $options['data'] : false); | ||
This comment has been minimized.
Sorry, something went wrong.
vlastv
Contributor
|
||
$builder->addViewTransformer(new BooleanToStringTransformer($options['value'])); | ||
} | ||
|
||
/** | ||
|
@@ -46,8 +51,8 @@ public function buildView(FormView $view, FormInterface $form, array $options) | |
*/ | ||
public function setDefaultOptions(OptionsResolverInterface $resolver) | ||
{ | ||
$emptyData = function (FormInterface $form, $clientData) { | ||
return $clientData; | ||
$emptyData = function (FormInterface $form, $viewData) { | ||
return $viewData; | ||
}; | ||
|
||
$resolver->setDefaults(array( | ||
|
Since this check has been removed, I get the TransformationFailedException from line 53 at every formField for which no default value is provided. In other words (correct me if I am wrong), now I have to always pass a default value to checkbox.
Shouldn't the transformer also handle null values?