From affeae238c3e5f4bbadc3b2c6761a356b7e33596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 11 Aug 2016 23:26:32 +0200 Subject: [PATCH] adding empty data on CFChoice And fixing a bug occuring because type of empty data are wrong. fix #23 --- CustomFields/CustomFieldChoice.php | 18 +++++++++--------- Form/Type/ChoiceWithOtherType.php | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index fa8ccffa5..d979e84b4 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -123,26 +123,26 @@ class CustomFieldChoice extends AbstractCustomField 'expanded' => true, 'multiple' => false, 'choices' => array( - 1 => 'Multiple', - 0 => 'Unique'), - 'empty_data' => 0, + '1' => 'Multiple', + '0' => 'Unique'), + 'empty_data' => '0', 'label' => 'Multiplicity' )) ->add(self::EXPANDED, 'choice', array( 'expanded' => true, 'multiple' => false, 'choices' => array( - 1 => 'Expanded', - 0 => 'Non expanded'), - 'empty_data' => 0, + '1' => 'Expanded', + '0' => 'Non expanded'), + 'empty_data' => '0', 'label' => 'Choice display' )) ->add(self::ALLOW_OTHER, 'choice', array( 'label' => 'Allow other', 'choices' => array( - 0 => 'No', - 1 => 'Yes'), - 'empty_data' => 0, + '0' => 'No', + '1' => 'Yes'), + 'empty_data' => '0', 'expanded' => true, 'multiple' => false )) diff --git a/Form/Type/ChoiceWithOtherType.php b/Form/Type/ChoiceWithOtherType.php index f6e295706..5520981d2 100644 --- a/Form/Type/ChoiceWithOtherType.php +++ b/Form/Type/ChoiceWithOtherType.php @@ -30,11 +30,13 @@ class ChoiceWithOtherType extends AbstractType $options['choices']['_other'] = $this->otherValueLabel; //ChoiceWithOther must always be expanded $options['expanded'] = true; + // adding a default value for choice + $options['empty_data'] = null; $builder ->add('_other', 'text', array('required' => false)) ->add('_choices', 'choice', $options) - ; + ; } /* (non-PHPdoc) @@ -45,7 +47,9 @@ class ChoiceWithOtherType extends AbstractType $resolver ->setRequired(array('choices')) ->setAllowedTypes(array('choices' => array('array'))) - ->setDefaults(array('multiple' => false)) + ->setDefaults(array( + 'multiple' => false, + )) ; }