Formular dinamic cu jQuery
Scris: Mie Iul 15, 2020
Salut
As dori sa fac un formular in care vreu sa pun pretul de transport in functie de greutate.
Si am greutatea minima , greutatea maxima ; cost transport
in functie de acesta greutate pot sa pun mai multe preturi de transport
Am creat tabelu carea arata cam asa:
si am creat si codul jQuery carea arata cam asa:
imi apare formularu fnctioneaza butoane + si - cand vreu sa adaug un alt rand dar din pacate nu mil salveaza dupa ce le adaug si le completez
partea de comanda ar fi cam asa
ma poti ajuta cu un sfat sa imi zici de ce nu salveaza setareea
sau daca ai vrun scrit din care ma pot inspira
As dori sa fac un formular in care vreu sa pun pretul de transport in functie de greutate.
Si am greutatea minima , greutatea maxima ; cost transport
in functie de acesta greutate pot sa pun mai multe preturi de transport
Am creat tabelu carea arata cam asa:
Cod: Selectaţi tot
<table id="price_per_kg" class="table table-striped table-bordered table-hover">
<thead>
<div class="panel-heading">
<h3 class="panel-title "><i class="fa fa-pencil"></i>{{ entry_rate_shipping }}</h3>
</div>
<tr>
<td width="30%">{{ entry_rate_min }}</td>
<td width="30%">{{ entry_rate_max}}</td>
<td width="30%">{{ entry_rate_cost }}</td>
<td> </td>
</tr>
</thead>
<tbody>
{% set price_per_kg_row = 0 %}
{% for price_per_kg in prices_per_kg %}
<tr id="price_per_kg_row{{ price_per_kg_row }}">
<td>
<input type="text" name="price_per_kg[{{ price_per_kg_row }}][kg_min]" value="{{ price_per_kg.kg_min }}" placeholder="{{ entry_rate_min }}" class="form-control"/>
</td>
<td>
<input type="text" name="price_per_kg[{{ price_per_kg_row }}][kg_max]" value="{{ price_per_kg.kg_max }}" placeholder="{{ entry_rate_max }}" class="form-control"/>
</td>
<td>
<input type="text" name="price_per_kg[{{ price_per_kg_row }}][kg_cost]" value="{{ price_per_kg.kg_cost }}" placeholder="{{ entry_rate_cost }}" class="form-control"/>
</td>
<td>
<button type="button" onclick="$('#price_per_kg_row{{ price_per_kg_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button>
</td>
</tr>
{% set price_per_kg_row = price_per_kg_row + 1 %}
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<td class="text-left">
<button type="button" onclick="addRow();" data-toggle="tooltip" title="{{ button_kg_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button>
</td>
</tr>
</tfoot>
</table>
Cod: Selectaţi tot
<script type="text/javascript"><!--
var price_per_kg_row = {{ price_per_kg_row }};
function addRow() {
html = '<tr id="price_per_kg_row' + price_per_kg_row + '">';
html += ' <td class="text-right"><input type="text" name="price_per_kg[' + price_per_kg_row + '][kg_min]" value="" placeholder="{{ entry_rate_min }}" class="form-control" /></td>';
html += ' <td class="text-right"><input type="text" name="price_per_kg[' + price_per_kg_row + '][kg_max]" value="" placeholder="{{ entry_rate_max }}" class="form-control" /></td>';
html += ' <td class="text-right"><input type="text" name="price_per_kg[' + price_per_kg_row + '][kg_cost]" value="" placeholder="{{ entry_rate_cost }}" class="form-control" /></td>';
html += ' <td class="text-left"><button type="button" onclick="$(\'#price_per_kg_row' + price_per_kg_row + '\').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
html += '</tr>';
$('#price_per_kg tbody').append(html);
price_per_kg_row++;
}
//--></script>
imi apare formularu fnctioneaza butoane + si - cand vreu sa adaug un alt rand dar din pacate nu mil salveaza dupa ce le adaug si le completez
partea de comanda ar fi cam asa
Cod: Selectaţi tot
if (isset($this->request->post['price_per_kg'])) {
$prices_per_kg = $this->request->post['price_per_kg'];
} elseif (isset($this->request->get['price_per_kg'])) {
$prices_per_kg = $this->request->get('price_per_kg');
} else {
$prices_per_kg = array();
}
$data['prices_per_kg'] = array();
foreach ($prices_per_kg as $price_per_kg) {
$data['prices_per_kg'][] = array(
'kg_min' => $price_per_kg['kg_min'],
'kg_max' => $price_per_kg['kg_max'],
'kg_price' => $price_per_kg['kg_price'],
);
}
sau daca ai vrun scrit din care ma pot inspira