From b4fafd3a81f86f9a6fafb9808b70b9340be66e3d Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 1 Nov 2021 15:47:15 -0300 Subject: [PATCH] experiencia con modal bootstrap --- curriculumsearch/src/main/resources/static/main.js | 85 ++++++++++++++++++++++++++++++++++++++----------------------------------------------- curriculumsearch/src/main/webapp/jsp/postulante-form.jsp | 49 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 78 insertions(+), 56 deletions(-) diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js index f16ce41..b2f3c1b 100644 --- a/curriculumsearch/src/main/resources/static/main.js +++ b/curriculumsearch/src/main/resources/static/main.js @@ -1,30 +1,48 @@ var cont_experiencia = 0; let cont_estudios = 0; let cont_tecnologia = 0; -function agregarFieldExpierncia(evt){ +const experiencias = []; +const estudios = []; +const tecnologias = []; +function agregarFieldExpierncia(){ + //recoger del form + const pairs = {}; + const formexp = document.querySelector("[name=experiencia-form]"); + const formData = new FormData(formexp); + for (const [name, value] of formData){ + pairs[name] = value + } + experiencias[cont_experiencia] = pairs; + formexp.reset(); + //imprimir lista actualizada + const div = document.querySelector("#experiencias") + const div1 = document.createElement('div'); + let content='" + div1.innerHTML = content + div.innerHTML = ''; + div.appendChild(div1); cont_experiencia++; - - const nee = document.createElement("div") - nee.innerHTML = ` - - - - - - - - - - - - `; - nee.className = "mb-3 col-5" - form.insertBefore(nee,btn) + } function eliminarExperiencia(event) { + //eliminar del array + console.log(event.target.parentElement.id.split("-")[1]) + experiencias[event.target.parentElement.id.split("-")[1]]=null + //eliminar en html event.target.parentElement.remove() } function serializeJSON (form) { @@ -33,37 +51,10 @@ function serializeJSON (form) { // Create an object to hold the name/value pairs const pairs = {}; - const experiencias = []; - const estudios = []; - const tecnologias = []; // Add each name/value pair to the object for (const [name, value] of formData) { - //los atributos no primitivos tiene una nomenclatura distinta en sus names - //ej.: experiencia-4-institucion == experencias[4].institucion - let codificacion = name.split("-") - if(codificacion.length==1){ - pairs[name] = value - } - else{ - switch (codificacion[0]) { - case "experiencia": - if(experiencias[codificacion[1]]==null) experiencias[codificacion[1]]={}; - experiencias[codificacion[1]][codificacion[2]] = value - break; - case "estudio": - if(estudios[codificacion[1]]==null) estudios[codificacion[1]]={}; - estudios[codificacion[1]][codificacion[2]] = value - break; - case "tecnologia": - if(tecnologias[codificacion[1]]==null) tecnologias[codificacion[1]]={}; - tecnologias[codificacion[1]][codificacion[2]] = value - break; - - default: - break; - } - } + pairs[name] = value } pairs["experiencias"] = experiencias.filter(exp => exp)//eliminacion de nulos pairs["estudios"] = estudios.filter(est => est)//eliminacion de nulos diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index db96a87..254a91d 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -70,20 +70,51 @@ - + +
+ +
- + - - + - - + + + \ No newline at end of file -- libgit2 0.26.0