Commit 284a731195b80bcd0f659267138d99849ab75d92
1 parent
1970c9b499
Exists in
master
validando los campos no requeridos hasta marcar el checkbox
Showing
5 changed files
with
44 additions
and
9 deletions
Show diff stats
src/AppBundle/Controller/AdscripcionController.php
| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | namespace AppBundle\Controller; |
| 10 | 10 | |
| 11 | 11 | use AppBundle\Entity\DocumentosVerificados; |
| 12 | +use Symfony\Component\Form\FormError; | |
| 12 | 13 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
| 13 | 14 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
| 14 | 15 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| ... | ... | @@ -43,10 +44,27 @@ class AdscripcionController extends Controller |
| 43 | 44 | $form = $this->createForm('AppBundle\Form\UserType'); |
| 44 | 45 | $form->handleRequest($request); |
| 45 | 46 | |
| 46 | - $form->get('escala')->getData(); | |
| 47 | 47 | |
| 48 | - if ($form->isSubmitted() && $form->isValid()) { | |
| 48 | + //valida el formulario de los campos que son no requeridos pero se vuelven | |
| 49 | + //requeridos al tildar el checkbox. | |
| 50 | + if ($form->isSubmitted()) { | |
| 51 | + if ($form->get('oposicion')->getData()) { | |
| 52 | + //var_dump($form); | |
| 53 | + if (!$form->get('fecha_oposicion')->getData()) { | |
| 54 | + $form->get('fecha_oposicion')->addError(new FormError('Fecha no puede estar en blanco')); | |
| 55 | + } | |
| 49 | 56 | |
| 57 | + if (!$form->get('escala')->getData()) { | |
| 58 | + $form->get('escala')->addError(new FormError('Si selecciona que tiene concurso de oposción, debe seleccionar a que escalafón lo aprobó')); | |
| 59 | + } | |
| 60 | + | |
| 61 | + if (!$form->get('documento_oposicion')->getData()) { | |
| 62 | + $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')); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + if ($form->isSubmitted() && $form->isValid()) { | |
| 50 | 68 | //Crear la solicitud de Servicio |
| 51 | 69 | $servicios = new DocenteServicio(); |
| 52 | 70 | |
| ... | ... | @@ -118,9 +136,8 @@ class AdscripcionController extends Controller |
| 118 | 136 | } |
| 119 | 137 | $adscripcion->setAnoAdscripcion($ano); |
| 120 | 138 | $adscripcion->setCorrelativoAdscripcion($numero); |
| 121 | - | |
| 122 | 139 | |
| 123 | - if ($form->get('escala')->getData()){ | |
| 140 | + if ($form->get('oposicion')->getData()){ | |
| 124 | 141 | $escala->setIdRolInstitucion($this->getUser()->getIdRolInstitucion()); |
| 125 | 142 | $escala->setFechaEscala($form->get('fecha_oposicion')->getData()); |
| 126 | 143 | $escala->setIdEscala($form->get('escala')->getData()); | ... | ... |
src/AppBundle/Controller/AscensoController.php
| ... | ... | @@ -686,7 +686,7 @@ class AscensoController extends Controller |
| 686 | 686 | 'idEstatus' => 2 |
| 687 | 687 | )); |
| 688 | 688 | |
| 689 | - //$documento->setIdEstatus($em->getRepository("AppBundle:Estatus")->findOneById($this->get('request')->request->get('reconocimiento'))); | |
| 689 | + $documento->setIdEstatus($em->getRepository("AppBundle:Estatus")->findOneById($this->get('request')->request->get('reconocimiento'))); | |
| 690 | 690 | |
| 691 | 691 | $servicio->setIdEstatus($this->getDoctrine()->getRepository('AppBundle:Estatus')->findOneById(4)); |
| 692 | 692 | $em->persist($servicio); | ... | ... |
src/AppBundle/Entity/Adscripcion.php
src/AppBundle/Entity/DocenteEscala.php
| ... | ... | @@ -55,7 +55,7 @@ class DocenteEscala |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * @var \AppBundle\Entity\TipoAscenso |
| 58 | - * | |
| 58 | + * @Assert\NotBlank()(groups={"Oposicion"}) | |
| 59 | 59 | * @ORM\ManyToOne(targetEntity="AppBundle\Entity\TipoAscenso") |
| 60 | 60 | * @ORM\JoinColumns({ |
| 61 | 61 | * @ORM\JoinColumn(name="id_tipo_escala", referencedColumnName="id", nullable=false) |
| ... | ... | @@ -67,7 +67,9 @@ class DocenteEscala |
| 67 | 67 | |
| 68 | 68 | /** @ORM\Column(type="date", nullable=false, options={"comment" = "Fecha de obtencion de la escala"}) |
| 69 | 69 | /** |
| 70 | - * @Assert\Date() | |
| 70 | + * | |
| 71 | + * @Assert\NotBlank()(groups={"Oposicion"}) | |
| 72 | + * @Assert\Date()(groups={"Oposicion"}) | |
| 71 | 73 | */ |
| 72 | 74 | private $fecha_escala; |
| 73 | 75 | ... | ... |
src/AppBundle/Form/UserType.php
| ... | ... | @@ -9,6 +9,9 @@ |
| 9 | 9 | |
| 10 | 10 | namespace AppBundle\Form; |
| 11 | 11 | |
| 12 | + | |
| 13 | +use Symfony\Component\Form\Deprecated\FormEvents; | |
| 14 | +use Symfony\Component\Form\FormEvent; | |
| 12 | 15 | use Symfony\Component\Validator\Constraints\Date; |
| 13 | 16 | use Symfony\Component\Validator\Constraints\File; |
| 14 | 17 | use Symfony\Component\Validator\Constraints\NotBlank; |
| ... | ... | @@ -118,11 +121,12 @@ class UserType extends AbstractType |
| 118 | 121 | ->add('oposicion', CheckboxType::class, array( |
| 119 | 122 | 'label' => '¿Tiene Concurso de Oposición?', |
| 120 | 123 | 'required' => false, |
| 124 | + 'mapped' => false, | |
| 121 | 125 | )) |
| 122 | 126 | |
| 123 | 127 | ->add('escala', EntityType::class, array( |
| 124 | 128 | 'label' => false, |
| 125 | - 'placeholder' => 'Seleccione escala a la que concurso', | |
| 129 | + 'placeholder' => 'Seleccione escala a la que concursó', | |
| 126 | 130 | 'required' => false, |
| 127 | 131 | 'attr' => array( |
| 128 | 132 | 'class' => 'esc_oposicion' |
| ... | ... | @@ -141,6 +145,13 @@ class UserType extends AbstractType |
| 141 | 145 | 'attr' => array( |
| 142 | 146 | 'class' => 'esc_oposicion' |
| 143 | 147 | ), |
| 148 | + 'placeholder' => array( | |
| 149 | + 'year' => 'Año', 'month' => 'Mes', 'day' => 'Día', | |
| 150 | + ), | |
| 151 | + 'validation_groups' => 'Oposicion', | |
| 152 | + 'constraints' => array( | |
| 153 | + new Date(), | |
| 154 | + ), | |
| 144 | 155 | 'years' => range(2003, date("Y")) |
| 145 | 156 | )) |
| 146 | 157 | ->add('documento_oposicion', FileType::class, array( |
| ... | ... | @@ -356,8 +367,12 @@ class UserType extends AbstractType |
| 356 | 367 | ; |
| 357 | 368 | |
| 358 | 369 | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 359 | 373 | } |
| 360 | - | |
| 374 | + | |
| 375 | + | |
| 361 | 376 | |
| 362 | 377 | |
| 363 | 378 | ... | ... |