Commit e8cc1338 authored by Mat's avatar Mat

form commande: parcourt les légumesSorted pour hydrater le sous-formulaire

parent d5ba27cf
......@@ -92,20 +92,26 @@ class MembreController extends MasterController
}
/**
* Le formulaire de commande
* Le formulaire de commande, formulaire imbriqué
* qui crée une commande et des commandeLégumes
*
* @var OffreLegumes $legume
*/
$commande = new Commande($offre, $user);
$legume = new CommandeLegumes();
//boucle//////
//$legume
//->setPrixUnitaire(2.6)
//->setUnite('botte')
//->setQuantite(3)
//->setPrix(7.8);
//////////
$commande->addCommandeLegumes($legume);
foreach ($currentOffre['legumesSorted'] as $legume)
{
dump($legume->getNom());
$item = new CommandeLegumes();
$item
->setPrixUnitaire($legume->getPrixUnitaire())
->setUnite($legume->getUnite())
->setQuantite(0.0)
->setPrix(0.0)
;
$commande->addCommandeLegumes($item);
}
$form = $this->createForm(CommandeType::class, $commande);
$form->handleRequest($request);
......
......@@ -12,54 +12,3 @@ $("#offre div.item")
$(this).transition({ scale: 1 }, 200, 'linear');
$(this).find('.overlay').transition({ opacity: 0 }, 200, 'linear');
});
/*
* Formulaire imbriqués, ajouter/enlever des légumes à la commande
* https://symfony.com/doc/3.4/form/form_collections.html
*/
let holder;
let addLink = $('<a href="#" class="add-legume">+</a>');
let newLi = $('<li></li>').append(addLink);
jQuery(document).ready(function() {
holder = $('ul.commandeLegumes');
holder.append(newLi);
holder.data('index', holder.find(':input').length);
addLink.on('click', function(e)
{
addForm(holder, newLi);
});
});
function addForm(holder, newLi)
{
let prototype = holder.data('prototype');
let index = holder.data('index');
let newForm = prototype;
// You need this only if you didn't set 'label' => false in your tags field in TaskType
// Replace '__name__label__' in the prototype's HTML to
// instead be a number based on how many items we have
// newForm = newForm.replace(/__name__label__/g, index);
// Replace '__name__' in the prototype's HTML to
// instead be a number based on how many items we have
newForm = newForm.replace(/__name__/g, index);
holder.data('index', index + 1);
let newFormLi = $('<li></li>').append(newForm);
newFormLi.append('<a href="#" class="remove-legume">x</a>');
newLi.before(newFormLi);
$('.remove-legume').click(function(e)
{
e.preventDefault();
$(this).parent().remove();
return false;
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment