Browse Source

Rewrote form cleaning

Brendan Abolivier 7 years ago
parent
commit
1663978d6c
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 changed files with 17 additions and 4 deletions
  1. 17
    4
      front/form.js

+ 17
- 4
front/form.js View File

357
 // Empties the form fields
357
 // Empties the form fields
358
 // return: nothing
358
 // return: nothing
359
 function cleanForm() {
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