From 284a731195b80bcd0f659267138d99849ab75d92 Mon Sep 17 00:00:00 2001 From: Wilmer Date: Tue, 7 Mar 2017 13:09:17 -0400 Subject: [PATCH] validando los campos no requeridos hasta marcar el checkbox --- src/AppBundle/Controller/AdscripcionController.php | 25 ++++++++++++++++++---- src/AppBundle/Controller/AscensoController.php | 2 +- src/AppBundle/Entity/Adscripcion.php | 1 + src/AppBundle/Entity/DocenteEscala.php | 6 ++++-- src/AppBundle/Form/UserType.php | 19 ++++++++++++++-- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/AppBundle/Controller/AdscripcionController.php b/src/AppBundle/Controller/AdscripcionController.php index 0545915..2812fc9 100644 --- a/src/AppBundle/Controller/AdscripcionController.php +++ b/src/AppBundle/Controller/AdscripcionController.php @@ -9,6 +9,7 @@ namespace AppBundle\Controller; use AppBundle\Entity\DocumentosVerificados; +use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\File\UploadedFile; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -43,10 +44,27 @@ class AdscripcionController extends Controller $form = $this->createForm('AppBundle\Form\UserType'); $form->handleRequest($request); - $form->get('escala')->getData(); - if ($form->isSubmitted() && $form->isValid()) { + //valida el formulario de los campos que son no requeridos pero se vuelven + //requeridos al tildar el checkbox. + if ($form->isSubmitted()) { + if ($form->get('oposicion')->getData()) { + //var_dump($form); + if (!$form->get('fecha_oposicion')->getData()) { + $form->get('fecha_oposicion')->addError(new FormError('Fecha no puede estar en blanco')); + } + if (!$form->get('escala')->getData()) { + $form->get('escala')->addError(new FormError('Si selecciona que tiene concurso de oposción, debe seleccionar a que escalafón lo aprobó')); + } + + if (!$form->get('documento_oposicion')->getData()) { + $form->get('documento_oposicion')->addError(new FormError('Si selecciona que tiene concurso de oposción, debe subir el digital de la aprobación del concurso')); + } + } + } + + if ($form->isSubmitted() && $form->isValid()) { //Crear la solicitud de Servicio $servicios = new DocenteServicio(); @@ -118,9 +136,8 @@ class AdscripcionController extends Controller } $adscripcion->setAnoAdscripcion($ano); $adscripcion->setCorrelativoAdscripcion($numero); - - if ($form->get('escala')->getData()){ + if ($form->get('oposicion')->getData()){ $escala->setIdRolInstitucion($this->getUser()->getIdRolInstitucion()); $escala->setFechaEscala($form->get('fecha_oposicion')->getData()); $escala->setIdEscala($form->get('escala')->getData()); diff --git a/src/AppBundle/Controller/AscensoController.php b/src/AppBundle/Controller/AscensoController.php index 964e6cc..0949def 100644 --- a/src/AppBundle/Controller/AscensoController.php +++ b/src/AppBundle/Controller/AscensoController.php @@ -686,7 +686,7 @@ class AscensoController extends Controller 'idEstatus' => 2 )); - //$documento->setIdEstatus($em->getRepository("AppBundle:Estatus")->findOneById($this->get('request')->request->get('reconocimiento'))); + $documento->setIdEstatus($em->getRepository("AppBundle:Estatus")->findOneById($this->get('request')->request->get('reconocimiento'))); $servicio->setIdEstatus($this->getDoctrine()->getRepository('AppBundle:Estatus')->findOneById(4)); $em->persist($servicio); diff --git a/src/AppBundle/Entity/Adscripcion.php b/src/AppBundle/Entity/Adscripcion.php index 85371e6..e312974 100644 --- a/src/AppBundle/Entity/Adscripcion.php +++ b/src/AppBundle/Entity/Adscripcion.php @@ -48,6 +48,7 @@ class Adscripcion /** @ORM\Column(type="date", nullable=false, options={"comment" = "Fecha de de Ingreso a la Institucion"}) /** * @Assert\Date() + * @Assert\NotBlank()(groups={"Oposicion"}) */ private $fecha_ingreso; diff --git a/src/AppBundle/Entity/DocenteEscala.php b/src/AppBundle/Entity/DocenteEscala.php index 89c23ba..f189352 100644 --- a/src/AppBundle/Entity/DocenteEscala.php +++ b/src/AppBundle/Entity/DocenteEscala.php @@ -55,7 +55,7 @@ class DocenteEscala /** * @var \AppBundle\Entity\TipoAscenso - * + * @Assert\NotBlank()(groups={"Oposicion"}) * @ORM\ManyToOne(targetEntity="AppBundle\Entity\TipoAscenso") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="id_tipo_escala", referencedColumnName="id", nullable=false) @@ -67,7 +67,9 @@ class DocenteEscala /** @ORM\Column(type="date", nullable=false, options={"comment" = "Fecha de obtencion de la escala"}) /** - * @Assert\Date() + * + * @Assert\NotBlank()(groups={"Oposicion"}) + * @Assert\Date()(groups={"Oposicion"}) */ private $fecha_escala; diff --git a/src/AppBundle/Form/UserType.php b/src/AppBundle/Form/UserType.php index bb59c9c..e6dc092 100644 --- a/src/AppBundle/Form/UserType.php +++ b/src/AppBundle/Form/UserType.php @@ -9,6 +9,9 @@ namespace AppBundle\Form; + +use Symfony\Component\Form\Deprecated\FormEvents; +use Symfony\Component\Form\FormEvent; use Symfony\Component\Validator\Constraints\Date; use Symfony\Component\Validator\Constraints\File; use Symfony\Component\Validator\Constraints\NotBlank; @@ -118,11 +121,12 @@ class UserType extends AbstractType ->add('oposicion', CheckboxType::class, array( 'label' => '¿Tiene Concurso de Oposición?', 'required' => false, + 'mapped' => false, )) ->add('escala', EntityType::class, array( 'label' => false, - 'placeholder' => 'Seleccione escala a la que concurso', + 'placeholder' => 'Seleccione escala a la que concursó', 'required' => false, 'attr' => array( 'class' => 'esc_oposicion' @@ -141,6 +145,13 @@ class UserType extends AbstractType 'attr' => array( 'class' => 'esc_oposicion' ), + 'placeholder' => array( + 'year' => 'Año', 'month' => 'Mes', 'day' => 'Día', + ), + 'validation_groups' => 'Oposicion', + 'constraints' => array( + new Date(), + ), 'years' => range(2003, date("Y")) )) ->add('documento_oposicion', FileType::class, array( @@ -356,8 +367,12 @@ class UserType extends AbstractType ; + + + } - + + -- 2.0.0