diff --git a/src/UnicaenAutoform/View/Helper/partial/input/plus_custom.phtml b/src/UnicaenAutoform/View/Helper/partial/input/plus_custom.phtml index 275e85ad2e9bf83fb84604ac610a93907586f37a..85ecd088b9d9c2a66b29bac4c714632902697db4 100644 --- a/src/UnicaenAutoform/View/Helper/partial/input/plus_custom.phtml +++ b/src/UnicaenAutoform/View/Helper/partial/input/plus_custom.phtml @@ -7,9 +7,11 @@ use UnicaenAutoform\Entity\Db\Champ; -$options = ($champ->getOptions() !== null)??explode(';', $champ->getOptions()); -$temp = ($reponse)?explode(';', $reponse):[]; -$temp = array_map(function ($s) { return "'".$s."'";}, $temp); +$options = ($champ->getOptions() !== null) ?? explode(';', $champ->getOptions()); +$temp = ($reponse) ? explode(';', $reponse) : []; +$temp = array_map(function ($s) { + return "'" . $s . "'"; +}, $temp); $array = "[" . implode(",", $temp) . "]"; ?> @@ -17,12 +19,13 @@ $array = "[" . implode(",", $temp) . "]"; <div class="autoform_container" id="container_<?php echo $champ->getId(); ?>"> <strong><?php echo $champ->getLibelle(); ?></strong> <span class="badge" id="count_element_<?php echo $champ->getId(); ?>"></span> - <?php if($champ->getTexte()) : ?> + <?php if ($champ->getTexte()) : ?> <p><?php echo $champ->getTexte(); ?></p> <?php endif; ?> <br> - <span id="<?php echo $champ->getId(); ?>" class="ajouter btn btn-primary" onclick="ajouter_PlusCustom(<?php echo $champ->getId(); ?>, readOptions('<?php echo $champ->getOptions(); ?>'))"> + <span id="<?php echo $champ->getId(); ?>" class="ajouter btn btn-primary" + onclick="ajouter_PlusCustom(<?php echo $champ->getId(); ?>, readOptions('<?php echo $champ->getOptions(); ?>'))"> <span class="icon icon-ajouter"></span> Ajouter </span> @@ -33,36 +36,34 @@ $array = "[" . implode(",", $temp) . "]"; function readOptions(optionsText) { let array = optionsText.split(';'); let fields = []; - for(let i = 0; i < array.length ; i++) { + for (let i = 0; i < array.length; i++) { fields.push(array[i].split('|')); } return fields; } - $(function() { + $(function () { let optionsText = '<?php echo $champ->getOptions(); ?>'; let fields = readOptions(optionsText); let reponses = '<?php echo $reponse; ?>'; - // console.log(fields); - let dictionnary = []; let blob = reponses.split('|'); - for(let i = 0 ; i < blob.length ; i++) { + for (let i = 0; i < blob.length; i++) { dictionnary[i] = blob[i].split(';'); } - readOptions(optionsText); let sid = <?php echo $champ->getId(); ?>; - console.log('HERE'); console.log(dictionnary); + console.log("Init du champ : " + sid); + console.log(dictionnary); if (dictionnary !== ['']) { for (let i = 0; i < dictionnary.length; i++) { - console.log(dictionnary[i]); - console.log(dictionnary[i][0]); if (dictionnary[i][0] !== "") { ajouter_PlusCustom(sid, fields, dictionnary[i]); + } else { + if (i === 0) ajouter_PlusCustom(sid, fields); } } } @@ -76,17 +77,17 @@ $array = "[" . implode(",", $temp) . "]"; } function getNbElements(id) { - let nb = $('div#container_'+ id +' div.element').length - $('span#count_element_' + id ).html(nb); + let nb = $('div#container_' + id + ' div.element').length + $('span#count_element_' + id).html(nb); } function getMaxElements(id) { - let elements = $('div#container_'+ id +' div.element') + let elements = $('div#container_' + id + ' div.element') let maximum = 0; - for( let i = 0 ; i < elements.length ; i++) { + for (let i = 0; i < elements.length; i++) { let thisId = elements[i].id.split("_")[2]; - if (thisId > maximum) maximum = thisId; + if (thisId > maximum) maximum = thisId; } return maximum; }