-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
122 lines (116 loc) · 4.74 KB
/
index.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
<!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;
}
.handle {
cursor: move;
margin-right: 10px;
}
</style>
</head>
<body>
<div class="container mt-4">
<h1 class="mb-4">List of Employees</h1>
<form id="employees">
<!-- Template row with Bootstrap classes -->
<div id="form-rows">
<div class="row g-3 align-items-center mb-4 form-row template-row">
<div class="col-auto handle">
<i class="fas fa-grip-vertical"></i>
</div>
<div class="col-auto">
<input type="text" class="form-control" name="employees[0][name]" placeholder="Enter employee name">
</div>
<div class="col-auto">
<select class="form-select" name="employees[0][dept]">
<option value="">Select Department</option>
<option value="IT">IT</option>
<option value="Sales & Marketing">Sales & Marketing</option>
<option value="HR">HR</option>
<option value="Operations">Operations</option>
</select>
</div>
<div class="col-auto">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="employees[0][perks]" value="Salary" id="checkboxSalary">
<label class="form-check-label" for="checkboxSalary">Salary</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="employees[0][perks]" value="Commission" id="checkboxCommission">
<label class="form-check-label" for="checkboxCommission">Commission</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input class="form-check-input" type="radio" name="employees[0][gender]" value="M" id="radioMale">
<label class="form-check-label" for="radioMale">Male</label>
</div>
</div>
<div class="col-auto">
<div class="form-check">
<input class="form-check-input" type="radio" name="employees[0][gender]" value="F" id="radioFemale">
<label class="form-check-label" for="radioFemale">Female</label>
</div>
</div>
<div class="col-auto">
<input type="text" class="form-control sort-order" name="employees[0][sort_order]" value="1" style="width: 100px">
</div>
<div class="col-auto">
<button type="button" class="btn btn-danger remove-row">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
</div>
</div>
<button id="add-row" class="btn btn-primary">Add Row</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() {
$('#employees').formRowRepeater({
templateRow: '.template-row',
addRowButton: '#add-row',
sortableContainer: '#form-rows',
rowClass: '.form-row',
handleClass: '.handle',
removeButtonClass: '.remove-row',
sortOrderClass: '.sort-order'
});
$('#employees').on('submit', function(event) {
event.preventDefault();
const beautifiedJson = $(this).serializeFormToJson();
$('#result').html(' <pre> ' + beautifiedJson + ' </pre>');
});
});
</script>
</body>
</html>