Skip to content

Commit

Permalink
Suppresses validation on Cancel in content edit/create
Browse files Browse the repository at this point in the history
  • Loading branch information
webhdx committed Nov 20, 2017
1 parent e1da558 commit f45f096
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Form/Type/Content/ContentEditType.php
Expand Up @@ -12,6 +12,8 @@
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
Expand Down Expand Up @@ -49,6 +51,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => 'content.cancel_button',
'attr' => ['formnovalidate' => 'formnovalidate'],
]);
$builder->addEventListener(FormEvents::POST_SUBMIT, [$this, 'suppressValidationOnCancel'], 900);
}
}

public function suppressValidationOnCancel(FormEvent $event) {
$form = $event->getForm();

if ($form->get('cancel')->isClicked()) {
$event->stopPropagation();
}
}

Expand Down

0 comments on commit f45f096

Please sign in to comment.