Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danielbonifacio
Last active November 22, 2018 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbonifacio/85351f88f560eae4ea6c1a29ddf59ee3 to your computer and use it in GitHub Desktop.
Save danielbonifacio/85351f88f560eae4ea6c1a29ddf59ee3 to your computer and use it in GitHub Desktop.
ajuda com objetos recursivos
import $ from 'jquery';
const FORMS = $('[valor=form]');
const data = {};
/**
* TODO: FAZER ESSE TREM CRIAR OBJETO SOZIN
* teste começa aqui
*/
let test = {};
const createCustomObject = (arr) => {
const object = arr.pop();
test = { test, object };
console.log(test);
if (arr.length > 0) {
createCustomObject(arr);
}
};
createCustomObject(['a', 'b', 'c']);
console.log(test);
/**
* teste termina aqui
* daqui pra baixo tudo ta OK (eu espero)
*/
const setData = (form) => {
const formData = {};
$(form).find('input:not([type=submit])').each((index, input) => {
const { name, value } = input;
formData[name] = value || null;
});
return formData;
};
const registerSubmit = (form) => {
const submit = (e) => {
e.preventDefault();
const { id } = e.target;
};
$(form).on('submit', submit);
};
const registerReactivity = (form) => {
const reactivity = (e) => {
const { name, value } = e.target;
data[form.id][name] = value;
};
$(form).find('input:not([type=submit])').on('keyup change', reactivity);
};
const registerData = (index, form) => {
data[form.id] = setData(form);
registerSubmit(form);
registerReactivity(form);
// console.log(data);
};
FORMS.each(registerData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment