// =========================================================================================== // Component: Form Tools // Module: Automatic Population // =========================================================================================== // Register the Form Tools - Automatic Population namspace registerNamespace("ft.ap"); // Define the PopulationJob object //------------------------------------------- // Constructor //------------------------------------------- ft.ap.PopulationJob = function(formInfo, populateEmpty) { this.formInfo = formInfo; this.populateEmpty = populateEmpty; } //------------------------------------------- // Public Methods //------------------------------------------- // Populates the form ft.ap.PopulationJob.prototype.run = function() { var self = this; // Find the form element var form = document.forms[self.formInfo.name]; if (!form) { // Can't find form, so exit return; } // Populate each field for(i in self.formInfo.fields) { var fieldInfo = self.formInfo.fields[i]; // If the field has no value if (!fieldInfo.value) { // If we should populate empty values if (self.populateEmpty) { // Set the value to the empty string fieldInfo.value = ""; } else { // If the field has a default value if (fieldInfo.defaultvalue) { fieldInfo.value = fieldInfo.defaultvalue; } else { // Skip this field continue; } } } // Unescape the field's value if (fieldInfo.value.constructor == String) { fieldInfo.value = fieldInfo.value.replace(/\+/g, " "); fieldInfo.value = unescape(fieldInfo.value); } else if (fieldInfo.value.constructor == Array) { for (var i=0; i