diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 5f36847..272f25e 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -5,6 +5,7 @@ import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.validation.ConstraintViolationException; +import javax.validation.Valid; import com.roshka.modelo.Experiencia; import com.roshka.modelo.Postulante; @@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.*; diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js index 4d113a8..c5b1fdc 100644 --- a/curriculumsearch/src/main/resources/static/main.js +++ b/curriculumsearch/src/main/resources/static/main.js @@ -4,13 +4,51 @@ let cont_tecnologia = 0; const experiencias = []; const estudios = []; const tecnologias = []; -function agregarFieldExpierncia(){ + +const formValidator = function () { + 'use strict' + + // Fetch all the forms we want to apply custom Bootstrap validation styles to + var forms = document.querySelectorAll('.needs-validation') + var expForm = document.querySelector('#agregar-exp') + + + // Loop over them and prevent submission + Array.prototype.slice.call(forms) + .forEach(function (form) { + form.addEventListener('submit', function (event) { + if (!form.checkValidity()) { + event.preventDefault() + event.stopPropagation() + } + + form.classList.add('was-validated') + }, false) + }) +} + +function agregarFieldExpierncia(event){ //recoger del form const pairs = {}; const formexp = document.querySelector("[name=experiencia-form]"); const formData = new FormData(formexp); const reconocimientos = [{},{},{}]; let pos_rec; + let returnFlag = false; + + formData.forEach((value, key)=>{ + if((key === "institucion" || key === "cargo" || key === "fechaDesde") + && value==="" && returnFlag == false){ + console.log(key, value) + returnFlag = true; + } + }); + + if(returnFlag===true){ + alert("Rellene Institucion, Fechas y Cargo como minimo"); + return; + } + for (const [name, value] of formData){ pos_rec = name.split("-");//rec-nombre-index if (pos_rec.length > 1) { @@ -45,7 +83,6 @@ function agregarFieldExpierncia(){ div.innerHTML = ''; div.appendChild(div1); cont_experiencia++; - } function eliminarExperiencia(event) { @@ -90,10 +127,14 @@ async function postData(url = '', data = {}) { }); return response; // parses JSON response into native JavaScript objects } - +formValidator() form = document.querySelector("form"); form.addEventListener("submit",(evt)=>{ - + // if (!form.checkValidity()) { + // evt.preventDefault() + // evt.stopPropagation() + // } + // form.classList.add('was-validated') postData('postulante', serializeJSON(form)) .then(response => { if(response.status==200 || response.status==302){ diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index d7690ed..25bdea6 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -13,47 +13,74 @@

Curriculum

-
+
- +
We'll never share your email with anyone else.
+
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
@@ -61,11 +88,17 @@
- + +
+ Luce Bien! +
- + +
+ Luce Bien! +
@@ -91,15 +124,20 @@