-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.html
More file actions
391 lines (340 loc) · 13.2 KB
/
example.html
File metadata and controls
391 lines (340 loc) · 13.2 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FormDataSaver (FDS) Demo</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
background: #f8f9fa;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
h1 {
color: #2c3e50;
margin-bottom: 10px;
}
.subtitle {
color: #7f8c8d;
margin-bottom: 30px;
font-style: italic;
}
.demo-info {
background: #e3f2fd;
border-left: 4px solid #2196f3;
padding: 15px;
margin-bottom: 25px;
border-radius: 4px;
}
.demo-info h3 {
margin-top: 0;
color: #1976d2;
}
form {
margin-bottom: 20px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #34495e;
}
input, textarea, select {
width: 100%;
padding: 12px;
border: 2px solid #e9ecef;
border-radius: 6px;
font-size: 16px;
transition: border-color 0.3s ease;
box-sizing: border-box;
}
input:focus, textarea:focus, select:focus {
outline: none;
border-color: #4CAF50;
}
textarea {
resize: vertical;
min-height: 100px;
}
.checkbox-group {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-top: 10px;
}
.checkbox-item, .radio-item {
display: flex;
align-items: center;
gap: 8px;
}
.checkbox-item input, .radio-item input {
width: auto;
margin: 0;
}
.radio-group {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 10px;
}
button {
background: #4CAF50;
color: white;
padding: 12px 30px;
border: none;
border-radius: 6px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background: #45a049;
}
.test-buttons {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin: 20px 0;
}
.test-buttons button {
background: #2196f3;
font-size: 14px;
padding: 8px 16px;
}
.test-buttons button:hover {
background: #1976d2;
}
.excluded-form {
background: #fff3cd;
border: 2px solid #ffc107;
padding: 20px;
border-radius: 6px;
margin-top: 30px;
}
.excluded-form h3 {
color: #856404;
margin-top: 0;
}
.status {
margin-top: 20px;
padding: 10px;
border-radius: 4px;
font-weight: bold;
}
.status.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.status.info {
background: #cce7ff;
color: #004085;
border: 1px solid #b3d7ff;
}
code {
background: #f1f3f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}
</style>
</head>
<body>
<div class="container">
<h1>FormDataSaver (FDS) Live Demo</h1>
<p class="subtitle">Test the auto-save functionality in real-time</p>
<div class="demo-info">
<h3>How to test:</h3>
<ol>
<li><strong>Fill out the form below</strong> - Notice data saves as you type</li>
<li><strong>Refresh the page</strong> - Your data will be restored with a banner</li>
<li><strong>Try the manual controls</strong> - Use buttons to save/restore/clear manually</li>
<li><strong>Submit the form</strong> - Data automatically clears after submission</li>
</ol>
</div>
<form id="demoForm" action="#" method="POST">
<div class="form-group">
<label for="fullName">Full Name</label>
<input type="text" id="fullName" name="fullName" placeholder="Enter your full name">
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="your@email.com">
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="tel" id="phone" name="phone" placeholder="(555) 123-4567">
</div>
<div class="form-group">
<label for="country">Country</label>
<select id="country" name="country">
<option value="">Select your country</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
<option value="ca">Canada</option>
<option value="au">Australia</option>
<option value="de">Germany</option>
<option value="fr">France</option>
<option value="jp">Japan</option>
<option value="other">Other</option>
</select>
</div>
<div class="form-group">
<label>Interests (check all that apply)</label>
<div class="checkbox-group">
<div class="checkbox-item">
<input type="checkbox" id="webdev" name="interests" value="web-development">
<label for="webdev">Web Development</label>
</div>
<div class="checkbox-item">
<input type="checkbox" id="design" name="interests" value="design">
<label for="design">Design</label>
</div>
<div class="checkbox-item">
<input type="checkbox" id="mobile" name="interests" value="mobile">
<label for="mobile">Mobile Apps</label>
</div>
<div class="checkbox-item">
<input type="checkbox" id="ai" name="interests" value="ai">
<label for="ai">Artificial Intelligence</label>
</div>
</div>
</div>
<div class="form-group">
<label>Experience Level</label>
<div class="radio-group">
<div class="radio-item">
<input type="radio" id="beginner" name="experience" value="beginner">
<label for="beginner">Beginner</label>
</div>
<div class="radio-item">
<input type="radio" id="intermediate" name="experience" value="intermediate">
<label for="intermediate">Intermediate</label>
</div>
<div class="radio-item">
<input type="radio" id="advanced" name="experience" value="advanced">
<label for="advanced">Advanced</label>
</div>
</div>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea id="message" name="message" placeholder="Tell us about your project or ask a question..."></textarea>
</div>
<button type="submit">Submit Form</button>
</form>
<div class="test-buttons">
<button onclick="manualSave()">Manual Save</button>
<button onclick="manualRestore()">Manual Restore</button>
<button onclick="manualClear()">Manual Clear</button>
<button onclick="showSavedKeys()">Show Saved Keys</button>
</div>
<div id="status"></div>
</div>
<div class="container excluded-form">
<h3>🚫 Excluded Form (Won't Auto-Save)</h3>
<p>This form has <code>data-fds-exclude</code> attribute, so it won't be auto-saved by FDS.</p>
<form data-fds-exclude>
<div class="form-group">
<label for="excludedInput">This won't be saved</label>
<input type="text" id="excludedInput" name="excludedInput" placeholder="Type here - won't be saved">
</div>
<button type="submit">Submit (No Auto-Save)</button>
</form>
</div>
<!-- FormDataSaver (FDS) - The magic line! -->
<script src="https://cdn.jsdelivr.net/gh/x0root/FormDataSaver@main/fds.js" defer></script>
<script>
// Demo functionality and event listeners
const statusDiv = document.getElementById('status');
const form = document.getElementById('demoForm');
function showStatus(message, type = 'info') {
statusDiv.innerHTML = `<div class="status ${type}">${message}</div>`;
setTimeout(() => {
statusDiv.innerHTML = '';
}, 3000);
}
function manualSave() {
if (typeof FDS !== 'undefined') {
FDS.save(form);
showStatus('✅ Form data manually saved!', 'success');
} else {
showStatus('⚠️ FDS not loaded yet. Try again in a moment.', 'info');
}
}
function manualRestore() {
if (typeof FDS !== 'undefined') {
FDS.restore(form);
showStatus('✅ Form data manually restored!', 'success');
} else {
showStatus('⚠️ FDS not loaded yet. Try again in a moment.', 'info');
}
}
function manualClear() {
if (typeof FDS !== 'undefined') {
FDS.clear(form);
showStatus('✅ Form data manually cleared!', 'success');
} else {
showStatus('⚠️ FDS not loaded yet. Try again in a moment.', 'info');
}
}
function showSavedKeys() {
if (typeof FDS !== 'undefined') {
const keys = FDS.list();
if (keys.length > 0) {
showStatus(`📝 Saved keys: ${keys.join(', ')}`, 'info');
} else {
showStatus('📝 No saved form data found', 'info');
}
} else {
showStatus('⚠️ FDS not loaded yet. Try again in a moment.', 'info');
}
}
// Listen for FDS events
document.addEventListener('DOMContentLoaded', function() {
// Give FDS time to load
setTimeout(() => {
if (form) {
form.addEventListener('fds:saved', function(e) {
console.log('FDS Event - Form saved:', e.detail);
});
form.addEventListener('fds:restored', function(e) {
console.log('FDS Event - Form restored:', e.detail);
showStatus('📥 Form data restored automatically!', 'success');
});
form.addEventListener('fds:cleared', function(e) {
console.log('FDS Event - Form cleared:', e.detail);
});
}
}, 1000);
});
// Handle form submission for demo
form.addEventListener('submit', function(e) {
e.preventDefault(); // Prevent actual submission for demo
showStatus('🎉 Form submitted successfully! (Demo mode - data would be sent to server)', 'success');
// In a real application, FDS would automatically clear the data after successful submission
// For this demo, we'll simulate it
setTimeout(() => {
if (typeof FDS !== 'undefined') {
FDS.clear(form);
showStatus('🧹 Form data automatically cleared after submission', 'info');
}
}, 2000);
});
</script>
</body>
</html>