Use a custom constraint/validator in symfony form type
<p>I'm trying to use a custom working validator in my form type but I get this error :</p>

<blockquote>
  <p>No default option is configured for constraint AppBundle\Validator\Constraints\DnsContent</p>
</blockquote>

<p>I have made this constraint + validator :</p>

<pre><code>// My constraint
/**
 * @Annotation
 */
class DnsContent extends Constraint
{
    public $message = 'fail';

    /**
     * {@inheritdoc}
     */
    public function validatedBy()
    {
         return 'dns_content';
    }
}

// My validator
class DnsContentValidator extends ConstraintValidator
{
    public function validate($type, Constraint $constraint)
    {
        switch ($type) {
            case 'A':
                return new Assert\Ip(['version' =&gt; '4']);
                break;
            case 'AAAA':
                return new Assert\Ip(['version' =&gt; '6']);
                break;
            case 'CNAME':
            case 'NS':
            case 'MX':
                return new Assert\Regex(['pattern' =&gt; '/^[[:alnum:]-\._]+$/u']);
                break;
            default:
                return false;
                break;
        }
    }
}
</code></pre>

<p>I'm trying to use it inside my form type like this</p>

<pre><code>$contentConstraints = function (FormInterface $form, $type) {
    $form-&gt;add('content', null, [
        'label'                 =&gt; 'form.content',
        'translation_domain'    =&gt; 'global',
        'constraints'           =&gt; new DnsContent($type),
    ]);
};
</code></pre>

<p>But I get the error I write above.
I don't understand how to fix this and if I use the correct way to use a custom constraint validator in a form type.</p>

<p>Thanks for your help</p>