Skip to content

Instantly share code, notes, and snippets.

@elnur
Last active August 29, 2015 14:01
Show Gist options
  • Save elnur/f16d9ae64557007821b2 to your computer and use it in GitHub Desktop.
Save elnur/f16d9ae64557007821b2 to your computer and use it in GitHub Desktop.
Symfony: Disabling HTML5 Form Validation Globally
<?php
namespace Acme\Form\Extension;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\Tag;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* @Service
* @Tag(name="form.type_extension", attributes={"alias":"form"})
*/
class NoValidateExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr'] = array_merge($view->vars['attr'], [
'novalidate' => 'novalidate',
]);
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment