|
|
|
@ -112,6 +112,27 @@ class DataUtils extends EventEmitter {
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Create a function to convert the serialize and convert the form data to JSON
|
|
|
|
|
* @param : $('#form_example');
|
|
|
|
|
* @return a JSON Stringify
|
|
|
|
|
*/
|
|
|
|
|
formDataToJSON(form) {
|
|
|
|
|
let object = {};
|
|
|
|
|
let formData = new FormData(form);
|
|
|
|
|
formData.forEach((value, key) => {
|
|
|
|
|
if (!object.hasOwnProperty(key)) {
|
|
|
|
|
object[key] = value;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!Array.isArray(object[key])) {
|
|
|
|
|
object[key] = [object[key]];
|
|
|
|
|
}
|
|
|
|
|
object[key].push(value);
|
|
|
|
|
});
|
|
|
|
|
let json = JSON.stringify(object);
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
//--------------------------
|
|
|
|
|
// event handlers
|
|
|
|
|
//--------------------------
|
|
|
|
|