瀏覽代碼

Rewrote form cleaning

Brendan Abolivier 7 年之前
父節點
當前提交
1663978d6c
簽署人: Brendan Abolivier <contact@brendanabolivier.com> GPG 金鑰 ID: 8EF1500759F70623
共有 1 個文件被更改,包括 17 次插入4 次删除
  1. 17
    4
      front/form.js

+ 17
- 4
front/form.js 查看文件

@@ -357,10 +357,23 @@ function getFormData() {
357 357
 // Empties the form fields
358 358
 // return: nothing
359 359
 function cleanForm() {
360
-	document.getElementById(prefix + '_' + items.name + '_input').value = '';
361
-	document.getElementById(prefix + '_' + items.addr + '_input').value = '';
362
-	document.getElementById(prefix + '_' + items.subj + '_input').value = '';
363
-	document.getElementById(prefix + '_' + items.text + '_textarea').value = '';
360
+	// Select the field
361
+	let index = 0;
362
+	if(labels) {
363
+		index = 1;
364
+	}
365
+
366
+	// Iterate over all the fields
367
+	for(let field in DOMFields) {
368
+		let el = DOMFields[field].children[index];
369
+		// If it's a <select> element, select the first element so it looks
370
+		// like a reset
371
+		if(!el.tagName.toLowerCase().localeCompare('select')) {
372
+			el.children[0].selected = true;
373
+		} else {
374
+			el.value = '';
375
+		}
376
+	}
364 377
 }
365 378
 
366 379