allow choosing empty value in CFLongChoice

This commit is contained in:
Julien Fastré 2015-12-17 22:07:28 +01:00
parent 9c622bc852
commit cbc66dc0f0
2 changed files with 8 additions and 2 deletions

View File

@ -19,7 +19,6 @@
namespace Chill\CustomFieldsBundle\CustomFields; namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Chill\CustomFieldsBundle\Entity\CustomField; use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository; use Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository;
@ -84,6 +83,8 @@ class CustomFieldLongChoice extends AbstractCustomField
'choices_as_values' => true, 'choices_as_values' => true,
'multiple' => false, 'multiple' => false,
'expanded' => false, 'expanded' => false,
'required' => $customField->isRequired(),
'placeholder' => 'Choose a value',
'group_by' => function(Option $option) use ($translatableStringHelper) { 'group_by' => function(Option $option) use ($translatableStringHelper) {
if ($option->hasParent()) { if ($option->hasParent()) {
return $translatableStringHelper->localize($option->getParent()->getText()); return $translatableStringHelper->localize($option->getParent()->getText());
@ -137,12 +138,16 @@ class CustomFieldLongChoice extends AbstractCustomField
return $this->templating return $this->templating
->render($template, array( ->render($template, array(
'values' => array($option) 'values' => $option === NULL ? array() : array($option)
)); ));
} }
public function serialize($value, \Chill\CustomFieldsBundle\Entity\CustomField $customField) public function serialize($value, \Chill\CustomFieldsBundle\Entity\CustomField $customField)
{ {
if ($value === NULL) {
return NULL;
}
if (!$value instanceof Option) { if (!$value instanceof Option) {
throw new \LogicException('the value should be an instance of ' throw new \LogicException('the value should be an instance of '
. 'Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, ' . 'Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, '

View File

@ -91,3 +91,4 @@ Text after the field: Texte après le champ
#custom field long choice #custom field long choice
Options key: Clé des options Options key: Clé des options
Choose a value: Choisissez une valeur