-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample2.html
175 lines (168 loc) · 7.45 KB
/
example2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Repeatable Form Row with Drag-and-Drop Sorting</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet" />
<style>
/* Custom styles specific to the form rows */
.form-row {
margin-bottom: 10px;
padding: 10px;
/* Add padding for better spacing */
background-color: #f8f9fa;
/* Light background color */
border: 1px solid #dee2e6;
/* Border color */
border-radius: .25rem;
/* Rounded corners */
}
.form-row input,
.form-row select {
margin-right: 10px;
}
.product-option-handle,
.product-option-value-handle {
cursor: move;
margin-right: 10px;
}
</style>
</head>
<body>
<div class="container mt-4">
<h1 class="mb-4">Product Options</h1>
<form id="product-options">
<!-- Template row with Bootstrap classes -->
<div id="product-options-rows">
<div class="mb-3 row required product-option-template product-option-row">
<div class="col-md-1 ">
<span class="product-option-handle">
<i class="fas fa-grip-vertical"></i>
</span>
</div>
<div class="col-md-8">
<div class="row">
<input type="hidden" name="options[0][id]" value="1">
<input type="text" name="options[0][name]" maxlength="255" class="form-control option-name">
</div>
<div class="row product-option-values">
<table class="table table-bordered table-striped mt-2 ">
<thead>
<tr>
<th width="5%"> </th>
<th width="30%">Name</th>
<th width="10%">Price</th>
<th width="10%">Prefix</th>
<th width="10%">Sort Order</th>
<th width="5%">Hidden</th>
<th width="5%">Default</th>
<th width="5%"> </th>
</tr>
</thead>
<tbody class="product-options-value-rows">
<tr class="product-option-value-row product-option-value-template">
<td>
<span class="product-option-value-handle">
<i class="fas fa-grip-vertical"></i>
</span>
</td>
<td>
<input type="hidden" name="options[0][values][0][id]" value="1">
<input type="text" name="options[0][values][0][name]" class="form-control product-option-value-name" data-rule-required="true">
</td>
<td>
<input type="text" name="options[0][values][0][price]" value="0.00" class="form-control product-option-value-price" data-rule-required="true" data-rule-number="true">
</td>
<td>
<select name="options[0][values][0][price_prefix]" class="form-select product-option-value-price-prefix">
<option value="+" selected>+</option>
<option value="-">-</option>
</select>
</td>
<td>
<input type="text" name="options[0][values][0][sort_order]" value="1" class="form-control product-option-value-sort-order" data-rule-required="true" data-rule-number="true">
</td>
<td>
<input type="checkbox" name="options[0][values][0][hidden]" value="YES" class="form-check-input product-option-value-hidden">
</td>
<td>
<input type="radio" name="options[0][values][0][default]" value="YES" class="form-check-input product-option-value-default" checked>
</td>
<td>
<button type="button" class="btn btn-danger product-option-value-remove">
<i class="fa-solid fa-xmark"></i>
</button>
</td>
</tr>
</tbody>
</table>
<button class="btn btn-primary product-option-value-add">Add Option Value</button>
</div>
</div>
<div class="col-md-1">
<input type="text" name="options[0][sort_order]" value="0" class="form-control product-option-sort-order" data-rule-required="true" data-rule-number="true">
</div>
<div class="col-md-1">
<input type="checkbox" name="options[0][hidden]" value="YES" class="form-check-input option-hidden">
</div>
<div class="col-md-1">
<button type="button" class="btn btn-danger product-option-remove">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
</div>
</div>
<button id="product-option-add" class="btn btn-primary">Add Option</button>
<button id="submit" class="btn btn-primary">Submit</button>
</form>
<div id="result" class="p-3 mt-4 bg-light border"></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="jquery.formRowRepeater.js"></script>
<script src="jquery.serializeFormToJson.js"></script>
<script>
$(document).ready(function() {
$('#product-options').formRowRepeater({
templateRow: '.product-option-template',
addRowButton: '#product-option-add',
sortableContainer: '#product-options-rows',
rowClass: '.product-option-row',
handleClass: '.product-option-handle',
removeButtonClass: '.product-option-remove',
sortOrderClass: '.product-option-sort-order',
level: 0,
afterAddedRow: function(row) {
row.formRowRepeater({
templateRow: '.product-option-value-template',
addRowButton: '.product-option-value-add',
sortableContainer: '.product-options-value-rows',
rowClass: '.product-option-value-row',
handleClass: '.product-option-value-handle',
removeButtonClass: '.product-option-value-remove',
sortOrderClass: '.product-option-value-sort-order',
level: 1
});
}
});
$('#product-options .product-option-values:first').formRowRepeater({
templateRow: '.product-option-value-template',
addRowButton: '.product-option-value-add',
sortableContainer: '.product-options-value-rows',
rowClass: '.product-option-value-row',
handleClass: '.product-option-value-handle',
removeButtonClass: '.product-option-value-remove',
sortOrderClass: '.product-option-value-sort-order',
level: 1
});
$('#product-options').on('submit', function(event) {
event.preventDefault();
const beautifiedJson = $(this).serializeFormToJson();
$('#result').html(' <pre> ' + beautifiedJson + ' </pre>');
});
});
</script>
</body>
</html>