THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 Choice multiple -> form

(07-03-2016 14:06:54)


Bonjour,

j'essaie de rajouter un champ dans mon formulaire de configuration
le champ est un choix multiple

    protected function addChoixMultipleField(array $translationKeys, array $fieldsIdKeys)
    {
        $this->formBuilder
            ->add("choix_multiple", "choice", array(
                'choices' => $this->getBrandList(),
                "label" => $this->readKey("choix_multiple", $translationKeys),
                "label_attr" => [
                    "for" => $this->readKey("choix_multiple", $fieldsIdKeys),
                    "help" => $this->readKey("help.choix_multiple", $translationKeys)
                ],
                "required" => true,
                "multiple" => true,
                "constraints" => array(
                    new NotBlank(),
                ),
                "data" => MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE),
            ))
        ;
    }

le rendu

{render_form_field form=$form field="choix_multiple" value=$choix_multiple}

au depart il n'était pas multiple, le formulaire s'affichait correctement
maintenant que j'ai rajouté 'multiple' =true

j'obtiens l'erreur suivante

TransformationFailedException in ChoicesToValuesTransformer.php line 50:
Expected an array.

une idée ?

Merci

Offline

#2 Re: Choice multiple -> form

(07-03-2016 14:09:43)


"data" => MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE),

data doit être un array.


OpenStudio Toulouse

Offline

#3 Re: Choice multiple -> form

(07-03-2016 14:12:06)


Merci Roadster31

je vais corriger wink

Offline

#4 Re: Choice multiple -> form

(07-03-2016 14:51:00)


je suis passé par TheliaStudio pour générer
mon config

du coups j'ai un problème avec la sauvegarde

j'ai modifié comme suite

            MonModule::setConfigValue($this->getBrandList(), is_bool($data["choix_multiple"]) ? (int) ($data["choix_multiple"]) : $data["choix_multiple"]);

mais j'obtiens cette erreur

ContextErrorException in Translator.php line 90:
Notice: Array to string conversion

Offline

#5 Re: Choice multiple -> form

(07-03-2016 14:52:44)


MonModule::setConfigValue(***$this->getBrandList()***, is_bool($data["choix_multiple"]) ? (int) ($data["choix_multiple"]) : $data["choix_multiple"]);

$this->getBrandList() ? Vraiment ?


OpenStudio Toulouse

Offline

#6 Re: Choice multiple -> form

(07-03-2016 15:02:38)


roadster31 wrote:
MonModule::setConfigValue(***$this->getBrandList()***, is_bool($data["choix_multiple"]) ? (int) ($data["choix_multiple"]) : $data["choix_multiple"]);

$this->getBrandList() ? Vraiment ?

heu non

MonModule::setConfigValue(MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE), is_bool($data["choix_multiple"]) ? (int) ($data["choix_multiple"]) : $data["choix_multiple"]);

je déclare

const 'CHOIX_MULTIPLE' = "choix_multiple[]";

j'ai la même erreur
pour la génération du form -> ok
mais pas la sauvegarde

ContextErrorException in Translator.php line 90:
Notice: Array to string conversion

Offline

#7 Re: Choice multiple -> form

(07-03-2016 15:38:33)


Bon j'ai fait marcher mon petit cerveau
j'ai modifié comme suit:

const 'CHOIX_MULTIPLE' = "choix_multiple[]";
    protected function addChoixMultipleField(array $translationKeys, array $fieldsIdKeys)
    {
        $this->formBuilder
            ->add("choix_multiple", "choice", array(
                'choices' => $this->getBrandList(),
                "label" => $this->readKey("choix_multiple", $translationKeys),
                "label_attr" => [
                    "for" => $this->readKey("choix_multiple", $fieldsIdKeys),
                    "help" => $this->readKey("help.choix_multiple", $translationKeys)
                ],
                "required" => true,
                "multiple" => true,
                "constraints" => array(
                    new NotBlank(),
                ),
                "data" => unserialize(MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE)),
            ))
        ;
    }
MonModule::setConfigValue(MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE), serialize($data["choix_multiple"]));

et c'est bon tongue

Offline

#8 Re: Choice multiple -> form

(07-03-2016 16:51:46)


Bon j'ai vidé le cache
et ça ne marche plus
j'ai de nouveau l'erreur
TransformationFailedException in ChoicesToValuesTransformer.php line 50:
Expected an array.

Offline

#9 Re: Choice multiple -> form

(07-03-2016 17:19:07)


Bon j'ai rajouté un test

        $dataValue = array();
        if(MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE))
        {
            $dataValue = unserialize(MonModule::getConfigValue(MonModuleConfigValue::CHOIX_MULTIPLE));
        }
.....
       "data" => $dataValue,
.....

maintenant c'est bon

Last edited by Debutant (07-03-2016 17:27:55)

Offline

#10 Re: Choice multiple -> form

(14-03-2017 16:44:46)


Bonjour,

J'essaye de mettre dans mon formulaire des choix multiples mais je n'arrive pas à saisir ton code et la manière dont tu l'as réalisé.

Merci,