Bonjour a tous,
j'ai un petit soucis,
j'ai un formulaire imbriqué entre deux entitées que j'ajoute de façon dynamique en jQuery.
voila mes formulaires :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 class PronosticsType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('start', DateTimeType::class, array( 'widget' => 'single_text', 'format' => 'yyyy-MM-dd', )) ->add('state', ChoiceType::class, array( 'choices' => array( 'En attente' => 0, 'Validé' => 1, 'Perdu' => 2, ), )) ->add('rank', HiddenType::class) ->add('info')->add('minbk')->add('maxbk') ->add('displaypublic', ChoiceType::class, array( 'choices' => array( 'Privé' => 0, 'Publique' => 1, ), )) ->add('bets', CollectionType::class, array( 'entry_type' => betsType::class, 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'prototype_name' => '__bets__' )) ->add('mise', HiddenType::class) ->add('save', SubmitType::class); /* new bets() */ }/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'BT\PlatformBundle\Entity\Pronostics' )); } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'bt_platformbundle_pronostics'; } }
j'ai un soucis lorsque que j'essaye d'ajouter en live des entité.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 class betsType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('matchs', null , array( 'attr' => array('class' => 'form-control'), 'label_attr' => array( 'class' => 'control-label' ) )) ->add('prono', null , array( 'attr' => array('class' => 'form-control'), 'label_attr' => array( 'class' => 'control-label' ), 'label'=>'Notre pronostic' )) ->add('analyse', TextareaType::class , array( 'attr' => array('class' => 'form-control', 'style' => 'height:200px'), 'label_attr' => array( 'class' => 'control-label' ) )) ->add('rank', null , array( 'attr' => array('class' => 'form-control'), 'label_attr' => array( 'class' => 'control-label' ), 'label'=>'Cote' )) ->add('category', EntityType::class, array('class' => 'BTPlatformBundle:Category','choice_label' => 'name','label' => 'Catégorie', 'attr' => array('class' => 'form-control'), 'label_attr' => array( 'class' => 'control-label' ))) ->add('at', DateTimeType::class, array( 'label' => 'Début', 'widget' => 'single_text', 'html5' => false, 'model_timezone' => 'Europe/Paris', 'format' => 'yyyy-MM-dd HH:mm', 'attr' => array('class' => 'form-control'), 'label_attr' => array( 'class' => 'control-label' ) )) ; //->add('matchs', null, array('label' => false), 'attr' => array('class' => 'tinymce')); }/** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'BT\PlatformBundle\Entity\bets' )); } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'bt_platformbundle_bets'; } }
enfaite , je peux ajouté autant de pronostics que je veux grace au bouton , par contre, un seul est envoyé en base de donnée.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 <div class="row"> <div class="col col-md-12"> <div class="forms"> <div id="formulaire"> {{ include("WebBundle::message.html.twig") }} {{ form_start(form) }} {{ form_errors(form) }} {{ form_errors(form.rank) }} {{ form_errors(form.info) }} {{ form_errors(form.start) }} <div class="form-group"> {{ form_label(form.info, "Intitulé", {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(form.info, {'attr': {'class': 'form-control'}}) }} </div> <!-- test --> <div id="email-fields-list" class="form-group wrapper-js" data-prototype="{{ form_widget(form.bets.vars.prototype)|e('html_attr') }}"> {% for bet in form.bets %} <div class="form-group bet"> <HR> {{ form_label(bet)}} {{ form_widget(bet)}} {% if loop.index != 1 %} <button type="button" class="btn btn-danger js-remove-bet">Supprimer un pronostic</button> {% endif %} </div> <HR> {% endfor %} </div> <!-- test --> <button type="button" class="btn btn-success" id="add-another-email">Ajouter un pronostic</button> <div class="form-group"> {{ form_label(form.start, "Date", {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(form.start, {'attr': {'class': 'form-control'}}) }} </div> <div class="form-group"> {{ form_label(form.minbk, "Bankroll minimum (en % )", {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(form.minbk, {'attr': {'class': 'form-control'}}) }} </div> <div class="form-group"> {{ form_label(form.maxbk, "Bankroll maximum (en % )", {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(form.maxbk, {'attr': {'class': 'form-control'}}) }} </div> <div class="form-group"> {{ form_label(form.state, "Etat", {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(form.state, {'attr': {'class': 'form-control'}}) }} </div> <div class="form-group"> {{ form_label(form.displaypublic, "Etat", {'label_attr': {'class': 'control-label'}}) }} {{ form_widget(form.displaypublic, {'attr': {'class': 'form-control'}}) }} </div> <div class="form-group"> {{ form_widget(form.save, {'attr': {'class': 'btn btn-secondary button-valid'}}) }} </div> {{ form_end(form) }} </div> </div> </div> </div> </div> <script type="text/javascript"> // keep track of how many email fields have been rendered var emailCount = '{{ form.bets | length }}'; var linkdelete = '<button type="button" class="btn btn-danger js-remove-bet">Supprimer un pronostic</button>'; jQuery(document).ready(function() { jQuery('#add-another-email').click(function() { var emailList = jQuery('#email-fields-list'); var newWidget = emailList.attr('data-prototype'); newWidget = newWidget.replace(/\$\$name\$\$/g, emailCount); console.log(newWidget); emailCount++; // var newLi = jQuery('<li></li>').html(newWidget); var newLi = jQuery('<li></li>').html(newWidget); newLi.appendTo(jQuery('#email-fields-list')); $('#email-fields-list').append(linkdelete); return false; }); var $wrapper = $('.wrapper-js'); $wrapper.on('click', '.js-remove-bet', function(e) { console.log("toto"); e.preventDefault(); $(this).closest('.bet') .fadeOut() .remove(); }); }) </script>
Je comprend pas pourquoi.
pouvez vous m'aider ?
Partager