<h3 dir="auto">Description</h3>
<p dir="auto">I have following form types: <code class="notranslate">ContactType.php</code> and  <code class="notranslate">SendContactType.php</code>.<br>
I have following entities with constraints: <code class="notranslate">Contact.php</code> and <code class="notranslate">SendContact.php</code>.</p>
<p dir="auto">They code for theose files can be seen at: <a href="https://gist.github.com/1199860">https://gist.github.com/1199860</a>.</p>
<p dir="auto">The problem is with the <code class="notranslate">something</code> field of <code class="notranslate">ContactType</code>.<br>
When that field is something simple (type <code class="notranslate">text</code> for example) everything works.<br>
If the value is shorter that 3 the error gets added to field's error list.</p>
<p dir="auto">But when that field is of type <code class="notranslate">repeated</code> something gets broken. When assertion<br>
fails the error gets added to the outermost form instead of  "something" field.</p>
<p dir="auto">Basically with this code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="        $form = $this-&gt;get('form.factory')-&gt;create(new SendContactType());
        $form-&gt;bindRequest($request);
        if (!$form-&gt;isValid()) {
            var_dump($form-&gt;getErrors());
        }"><pre class="notranslate"><code class="notranslate">        $form = $this-&gt;get('form.factory')-&gt;create(new SendContactType());
        $form-&gt;bindRequest($request);
        if (!$form-&gt;isValid()) {
            var_dump($form-&gt;getErrors());
        }
</code></pre></div>
<p dir="auto">A non-empty array is unexpectedly dumped with the error/message that shouldn't be there but down the tree.</p>
<h3 dir="auto">My analysis</h3>
<p dir="auto">Basically what happens in this case is that the <code class="notranslate">propertyPath</code> put together during validation graph walking doesn't match<br>
any of the patterns later generated in <code class="notranslate">DegelatingValidator::buildFormPathMapping()</code> etc. This happens<br>
when a form embeds another form containing a type <code class="notranslate">repeated</code> field.</p>
<p dir="auto">The propertyPath generated for <code class="notranslate">something</code> field is <code class="notranslate">string(32) "children[contact].data.something"</code>.<br>
The patterns DelegatingValidator generates and tries to match it against:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="string(25) &quot;/^children\.data\.(?!\w)/&quot;
string(30) &quot;/^children\.data\.agree(?!\w)/&quot;
string(36) &quot;/^children\[contact\]\.data\.(?!\w)/&quot;
string(49) &quot;/^children\[contact\]\[something\]\.data\.(?!\w)/&quot;
string(54) &quot;/^children\[contact\]\[something\]\.data\.first(?!\w)/&quot;
string(55) &quot;/^children\[contact\]\[something\]\.data\.second(?!\w)/&quot;
string(41) &quot;/^children\[contact\]\[something\](?!\w)/&quot;
string(43) &quot;/^children\[contact\]\.data\.message(?!\w)/&quot;
string(28) &quot;/^children\[contact\](?!\w)/&quot;"><pre class="notranslate"><code class="notranslate">string(25) "/^children\.data\.(?!\w)/"
string(30) "/^children\.data\.agree(?!\w)/"
string(36) "/^children\[contact\]\.data\.(?!\w)/"
string(49) "/^children\[contact\]\[something\]\.data\.(?!\w)/"
string(54) "/^children\[contact\]\[something\]\.data\.first(?!\w)/"
string(55) "/^children\[contact\]\[something\]\.data\.second(?!\w)/"
string(41) "/^children\[contact\]\[something\](?!\w)/"
string(43) "/^children\[contact\]\.data\.message(?!\w)/"
string(28) "/^children\[contact\](?!\w)/"
</code></pre></div>
<p dir="auto">The last one in this list is first that matches and that's why the error gets added to form, but it really should match earlier.</p>
<p dir="auto"><strong>Description</strong><br>
New feature request has start with the blog post : <a href="https://symfony.com/blog/new-in-symfony-4-1-form-field-help" rel="nofollow">Form field help</a>. It's a great post that explain how to extend a form to add a custom option <code class="notranslate">help</code> to show help message. I asked myself how to add this help message in an item choice of choiceType form. I wanted to make that like a <code class="notranslate">choice_attr</code> and callable function. But I cant. I fact ChoiceType <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php#L371">create</a> his children fields (Radio or Checkbox) with <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/ChoiceList/View/ChoiceView.php">ChoiceView</a> class and we can't add your custom options.</p>
<p dir="auto">In resume we can't extend choice_options like this:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="        $builder
            -&gt;add('dilem', ChoiceType::class, [
                'choices'     =&gt; [
                    'foo' =&gt; false,
                    'bar' =&gt; true,
                ],
                'choice_options' =&gt; function ($value, $key, $index) {
                    if ($value) {
                        return ['help' =&gt; 'My Help message'];
                    }
                },
                'expanded'      =&gt; true,
                'multiple'      =&gt; false,
            ]) ;"><pre class="notranslate">        <span class="pl-s1"><span class="pl-c1">$</span>builder</span>
            -&gt;<span class="pl-en">add</span>(<span class="pl-s">'dilem'</span>, <span class="pl-v">ChoiceType</span>::class, [
                <span class="pl-s">'choices'</span>     =&gt; [
                    <span class="pl-s">'foo'</span> =&gt; <span class="pl-c1">false</span>,
                    <span class="pl-s">'bar'</span> =&gt; <span class="pl-c1">true</span>,
                ],
                <span class="pl-s">'choice_options'</span> =&gt; <span class="pl-k">function</span> (<span class="pl-s1"><span class="pl-c1">$</span>value</span>, <span class="pl-s1"><span class="pl-c1">$</span>key</span>, <span class="pl-s1"><span class="pl-c1">$</span>index</span>) {
                    <span class="pl-k">if</span> (<span class="pl-s1"><span class="pl-c1">$</span>value</span>) {
                        <span class="pl-k">return</span> [<span class="pl-s">'help'</span> =&gt; <span class="pl-s">'My Help message'</span>];
                    }
                },
                <span class="pl-s">'expanded'</span>      =&gt; <span class="pl-c1">true</span>,
                <span class="pl-s">'multiple'</span>      =&gt; <span class="pl-c1">false</span>,
            ]) ;</pre></div>
<p dir="auto">I want to modify the code and create the pull request but can someone can accompany me to do it properly ?</p>