Bonjour,

Sur ce lien, vous pouvez tester le systeme sur le quel je travaille et ou j'ai un problème à résoude :

https://jsfiddle.net/1d74bm29/

Comme vous pourrez le voir j'ai plusieurs tables. Sur chaque table je peux rajouter des lignes ou en supprimer.
La suppression de le ligne fonctionne parfaitement.
par contre l'ajout de ligne pose un problème. Elle fonctionne mais quand on ajoute une ligne, sur chaque table, un ligne est rajouter.

Mon problème est d'ajouter une ligne uniquement dans la table que je souhaite.

Pour etre plus concret : La table checkbox par exemple.
Si je clique sur le bouton ajout (en base de la table à droite), il ajoute (ne fonctionne pas sur jiddle) une ligne mais pas uniquement dans la table checbox mais dans toutes les autres tables.

Le développement à été fait en php dont voici le code. Cela vous aidera peut être à me dire ce que je dois faire pour résoudre ce probleme.

Merci de votre aide, je ne suis pas terrbile en js.
Désolé il est un peu long !

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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
 
      $content = '<div class="adminformTitle">
                   <div class="separator"></div>
                   <div class="row">
                 ';
      $content .= '
                    <div class="col-sm-2 float-md-left">
                      <ul class="nav nav-pills nav-stacked" id="option">
                 ';
      $i = 1;
 
      foreach($option_attributes_name as $value) {
        $content .= '    <li class="col-md-12"><a href="#tab-option' . $i . '" data-toggle="tab"><i class="fa fa-minus-circle"></i> ' . $value['name'] . '</a></li>';
        $i++;
      }
 
      $content .='    </ul>
                    </div>
                ';
 
      $content .= '<div class="col-sm-10 float-md-right">';
 
 
      $Qoption = $this->app->db->prepare('select option_id,
                                                type
                                          from :table_test_products_options_attributes
 
                                         ');
      $Qoption->execute();
 
      $i = 0;
 
      while ($Qoption->fetch()) {
 
        $content .= '<div id="tab-option'. $Qoption->value('option_id') . '"><h4>' . $Qoption->value('type') . '</h4>';
 
 
        $content .= '
                        <table width="100%" cellpadding="5" cellspacing="0" border="0">
                          <tr>
                            <td><table class="table table-sm table-hover table-striped table-hover" id="option-value' . $i . '">
                              <thead>
                                <tr>
                                  <td>' . $this->app->getDef('table_heading_option_value') . '</td>
                                  <td>' . $this->app->getDef('table_heading_stock_quantity') . '</td>
                                  <td>' . $this->app->getDef('table_heading_subtract_stock') . '</td>
                                  <td>' . $this->app->getDef('table_heading_price') . '</td>
                ';
 
        if (MODE_B2B_B2C == 'true') {
          $content .= '           <td>' . $this->app->getDef('table_heading_customers_group') . '</td>';
        }
 
        $content .= '             <td>' . $this->app->getDef('table_heading_point') . '</td>
                                  <td>' . $this->app->getDef('table_heading_weight') . '</td>
                                  <td>' . $this->app->getDef('table_heading_action') . '</td>
                                </tr>
                              </thead>
                              <tbody>
                  ';
 
 
        $QoptionsValue = $this->db->prepare('select  poav.products_option_value_id,
                                                      poav.option_value_id,
                                                      poav.quantity,
                                                      poav.subtract,
                                                      poav.price,
                                                      poav.price_prefix,
                                                      poav.points,
                                                      poav.points_prefix,
                                                      poav.weight,
                                                      poav.weight_prefix,
 
                                                      po.products_option_id,
                                                      po.products_id,
                                                      po.option_id,
                                                      po.value,
                                                      po.required
                                         from :table_test_products_option_value poav,
                                              :table_test_products_option po
                                         where poav.products_option_id = po.products_option_id
                                         and poav.products_id = po.products_id
                                         and poav.products_id = :products_id
                                         and poav.option_id = :option_id
                                       ');
        $QoptionsValue->bindInt(':option_id', $Qoption->valueInt('option_id'));
        $QoptionsValue->bindInt(':products_id', $_GET['pID']);
        $QoptionsValue->execute();
 
        $n = 0;
 
        while ($QoptionsValue->fetch()) {
          $attributes_name =  $this->getProductsOptionsAttributesValueName($Qoption->valueInt('option_id'), $QoptionsValue->value('option_value_id'));
 
          $content .= '            <tr id="option-value-row' . $n .'">';
 
          $content .= HTML::hiddenField('product_option[' . $n .'][product_option_id]', $QoptionsValue->valueInt('option_value_id'));
          $content .= HTML::hiddenField('product_option[' . $n .'][option_id]', $QoptionsValue->valueInt('option_value_id'));
          $content .= HTML::hiddenField('product_option[' . $n .'][type]', $Qoption->value('type'));
 
 
          if ($Qoption->value('type') == 'radio') {
            $content .= '<td> ' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]', $attributes_name, $QoptionsValue->valueInt('option_value_id')) . '</td> ';
          }
 
          if ($Qoption->value('type') == 'checkbox') {
            $content .= '<td>' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]', $attributes_name, $QoptionsValue->valueInt('option_value_id')) . '  </td>';
          }
 
//verified if it's correct
          if ($Qoption->value('type') == 'text') {
            $content .= $Qoption->value('type') . '
                                    <td>
                                      ' . HTML::inputField('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]',  null, '60', '5') . '
                                    </td>
                        ';
          }
 
 
          if ($Qoption->value('type') == 'select') {
            $content .= '<td>' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]', $attributes_name, $QoptionsValue->valueInt('option_value_id')) . '</td>';
          }
 
//verified if it's correct
          if ($Qoption->value('type') == 'textarea') {
            $content .= '
                                    <td>
                                      ' . HTML::textAreaField('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]',  null, '60', '5') . '
                                    </td>
                        ';
          }
 
//verified if it's correct
          if ($Qoption->value('type') == 'file') {
            $content .= '
                                    <td>
                                      ' . HTML::fileField('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]',  null) . '
                                    </td>
                        ';
          }
 
//verified if it's correct
          if ($Qoption->value('type') == 'date') {
            $content .= '
                                    <td>
                                      ' . HTML::textAreaField('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]',  null, '60', '5') . '
                                    </td>
                        ';
          }
 
//verified if it's correct
          if ($Qoption->value('type') == 'time') {
            $content .= '
                                    <td>
                                      ' . HTML::textAreaField('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]',  null, '60', '5') . '
                                    </td>
                        ';
          }
 
          if ($Qoption->value('type') == 'datetime') {
            $content .= '
                                    <td>
                                      ' . HTML::textAreaField('product_option[' . $n .'][product_option_value][' . $n . '][option_value_id]',  null, '60', '5') . '
                                    </td>
                        ';
          }
 
          $content .= '
                                  <td>' . HTML::inputField('"product_option[' . $n .'][product_option_value]n[' . $n .'][quantity]', $QoptionsValue->value('quantity')) . '</td>
                                  <td>' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n .'][subtract]', $substract_stock_attributes_option_array, $QoptionsValue->value('subtract')) . '</td>
                                  <td>
                                    ' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n .'][price_prefix]', $price_prefix_attributes_option_array, $QoptionsValue->value('price_prefix')) . '<br />
                                    ' . HTML::inputField('product_option[' . $n .'][product_option_value][' . $n .'][price]', '') . '
                                  </td>
                    ';
 
          if (MODE_B2B_B2C == 'true') {
            $content .= '         <td>' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n .'][customers_group_id]', GroupsB2BAdmin::getAllGroups(), $customers_id) . '</td>';
          }
 
          $content .= '
                                  <td>
                                    ' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n .'][points_prefix]', $price_prefix_attributes_option_array, $QoptionsValue->value('points_prefix')) . '<br />
                                    ' . HTML::inputField('product_option[' . $n .'][product_option_value][' . $n .'][points]', $QoptionsValue->value('points')) . '
                                  </td>
                                  <td>
                                    ' . HTML::selectMenu('product_option[' . $n .'][product_option_value][' . $n .'][weight_prefix]', $price_prefix_attributes_option_array, $QoptionsValue->value('weight_prefix')) . '<br />
                                    ' . HTML::inputField('product_option[' . $n .'][product_option_value][' . $n .'][weight]', $QoptionsValue->value('weight')) . '
                                  </td>
                    ';
//remove row
          $content .= '                
                                  <td class="text-md-right" width="20"><button type="button" onclick="$(\'#option-value-row' . $n . '\').remove();" data-toggle="tooltip" rel="tooltip" title="" class="btn btn-danger" data-original-title="Remove"><i class="fa fa-minus-circle"></i></button>
                                </tr>
                    ';
          $n++;
        }
 
 
 
 
        $content .= '
                            </tbody>
                            <tfoot>
                              <tr>
                                <td colspan="7"></td>
                                <td class="text-right"><button type="button" onclick="addOptionValue(' . $i . ');" data-toggle="tooltip" title="' . $this->app->getDef('button_add') . '" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
                              </tr>
                            </tfoot>
                          </table></td>
                        </tr>
                      </table>
                    </div>
                ';
      }
 
      $content .= '
                    </div>
                  </div>
                </div>
                ';
 
 
      $configure_button = $this->app->getDef('button_configure');
 
      $tab_title = $this->app->getDef('tab_products_attributes_option');
      $title = $this->app->getDef('text_products_attributes_option');
      $customers_group = GroupsB2BAdmin::getAllGroups();
 
 
 
      $output = <<<EOD
<!-- ######################## -->
<!-- Start ProuctsAttributesNew APP  -->
<!-- ######################## -->
 
<div class="tab-pane" id="section_ProductsAttributesNewApp_content">
  <div class="mainTitle">
    <span class="col-md-10">{$title}</span>
    <span class="col-md-2 text-md-right">{$configure_button}</span>
  </div>
  {$content}
</div>
 
<script type="text/javascript"><!--
 
  var option_value_row = {$n};
 
  function addOptionValue(option_row) {
    html  = '<tr id="option-value-row' + option_value_row + '">';
 
    html += '  <td><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_value_id]" class="form-control">';
    html += $('#option-values' + option_row).html();
    html += '  </select><input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][product_option_value_id]" value="" /></td>';
    html += '  <td class="text-md-right"><input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][quantity]" value="" placeholder="entry_quantity" class="form-control" /></td>';
 
    html += '  <td><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][subtract]" class="form-control">';
    html += '    <option value="1">Yes</option>';
    html += '    <option value="0">No</option>';
    html += '  </select>';
    html += '  </td>';
    html += '  <td class="text-md-right"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][price_prefix]" class="form-control">';
    html += ' <td class="text-md-right"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][customers_group_id]" class="form-control">';
 
    html +=  '</select>';
    html +=  '</td>';
    html += '    <option value="+">+</option>';
    html += '    <option value="-">-</option>';
    html += '  </select>';
    html += '  <input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][price]" value="" placeholder="entry_price" class="form-control" /'>';'
    html += '  </td>';
 
    html += '  <td class="text-md-right"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][points_prefix]" class="form-control">';
    html += '    <option value="+">+</option>';
    html += '    <option value="-">-</option>';
    html += '  </select>';
    html += '  </td>';
 
    html += '  <input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][points]" value="" placeholder="entry_points" class="form-control" /></td>';
    html += '  <td class="text-md-right"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][weight_prefix]" class="form-control">';
    html += '    <option value="+">+</option>';
    html += '    <option value="-">-</option>';
    html += '  </select>';
 
    html += '  <input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][weight]" value="" placeholder="entry_weight" class="form-control" /></td>';
    html += '  <td class="text-md-right"><button type="button" onclick="$(\'#option-value-row' + option_value_row + '\').remove();" data-toggle="tooltip" rel="tooltip" title="button_remove" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
 
    html += '</tr>';
 
    $('#option-value' + option_row + ' tbody').append(html);
 
 
    option_value_row++;
  }
 
//--></script>
 
<!-- ######################## -->
<!--  End ProuctsAttributesNew APP   -->
<!-- ######################## -->
<br />
EOD;