<p dir="auto">It would be useful if view attributes could be passed to individual <code class="notranslate">choice</code> field options in a similar way as <code class="notranslate">attr</code> for most field types. Currently it seems not to be possible without duplicating both <code class="notranslate">ChoiceList</code> PHP class and duplicating both <code class="notranslate">choice_widget</code> and <code class="notranslate">widget_choice_options</code> template blocks.</p>
<p dir="auto">If the core form module supported (arbitrary) attrs in choice options, it would allow easy extension of the core <code class="notranslate">choice</code> field type for custom types. Custom data could be passed to the template, allowing HTML like:</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;select name=&quot;search_engine_selection&quot;&gt;
    &lt;option value=&quot;google&quot; data-url=&quot;google_logo.gif&quot;&gt;Google&lt;/option&gt;
    &lt;option value=&quot;bing&quot; data-url=&quot;bing_logo.gif&quot;&gt;Bing&lt;/option&gt;
&lt;/select&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">select</span> <span class="pl-c1">name</span>="<span class="pl-s">search_engine_selection</span>"<span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">option</span> <span class="pl-c1">value</span>="<span class="pl-s">google</span>" <span class="pl-c1">data-url</span>="<span class="pl-s">google_logo.gif</span>"<span class="pl-kos">&gt;</span>Google<span class="pl-kos">&lt;/</span><span class="pl-ent">option</span><span class="pl-kos">&gt;</span>
    <span class="pl-kos">&lt;</span><span class="pl-ent">option</span> <span class="pl-c1">value</span>="<span class="pl-s">bing</span>" <span class="pl-c1">data-url</span>="<span class="pl-s">bing_logo.gif</span>"<span class="pl-kos">&gt;</span>Bing<span class="pl-kos">&lt;/</span><span class="pl-ent">option</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">select</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">In my example, <code class="notranslate">data-url</code> would have been passed as an attribute to each option.</p>
<p dir="auto">It would be nice to be able to define extra HTML attributes for choices in a choice list that are added to the <code class="notranslate">option</code> or <code class="notranslate">input</code> tags.</p>
<p dir="auto">Origin of this ticket: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3393283" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/3456" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/3456/hovercard" href="https://github.com/symfony/symfony/issues/3456">#3456</a></p>