Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mathieu
potage
Commits
e8cc1338
Commit
e8cc1338
authored
Sep 18, 2018
by
Mat
Browse files
form commande: parcourt les légumesSorted pour hydrater le sous-formulaire
parent
d5ba27cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/PotageBundle/Controller/MembreController.php
View file @
e8cc1338
...
...
@@ -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
);
...
...
src/PotageBundle/Resources/views/Membre/today.js
View file @
e8cc1338
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment