<br><br><div><span class="gmail_quote">On 9/17/07, <b class="gmail_sendername">Hermann Himmelbauer</b> &lt;<a href="mailto:dusty@qwer.tk">dusty@qwer.tk</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
Am Samstag, 15. September 2007 18:08 schrieb Jesper Petersen:<br>&gt; Hello!I&#39;m trying to implement a DropdownWidget for my country list. In my<br>&gt; app i&#39;d like to have a dropdown menu where a user can choose a country (for
<br>&gt; my main content object, a job). My vocabulary is created from a list of<br>&gt; strings, and stored in a local utility:<br>&gt;<br>&gt;<br>&gt; SimpleVocabulary.fromValues( [u&#39;AD&#39;, u&#39;AE&#39;, &#39;AF&#39;, ...] )
<br>&gt;<br>&gt;<br>&gt; But in my dropdown widget i want to display the country name for each<br>&gt; option too.. and not just the same value on both the value attribute and<br>&gt; inside the element:<br>&gt;<br>&gt; &lt;option value=&quot;AD&quot;&gt;Andorra&lt;/option&gt;
<br><br>Perhaps I misunderstand your question, but AFAIK vocabulary support this<br>scenario. In my application, I also have a country drop-down that is in my<br>case filled from a relational database. The vocabulary looks like this:
<br><br>def landVocabulary(obj):<br> &nbsp; &nbsp;&quot;&quot;&quot;Get ktoids and ktonrs from session&quot;&quot;&quot;<br> &nbsp; &nbsp;session = zalchemy.getSession()<br> &nbsp; &nbsp;laender = session.query(Land)<br> &nbsp; &nbsp;laender_terms = []<br> &nbsp; &nbsp;for n, land in enumerate(laender):
<br> &nbsp; &nbsp; &nbsp; &nbsp;laender_terms.append(vocabulary.SimpleVocabulary.\<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createTerm(land.landid,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://land.name">
land.name</a>))<br> &nbsp; &nbsp;return vocabulary.SimpleVocabulary(laender_terms)<br><br># Make function a vocabulary factory<br>alsoProvides(landVocabulary, IVocabularyFactory)<br><br>and in my configuration:<br><br> &nbsp; &nbsp;&lt;utility
<br> &nbsp; &nbsp; &nbsp; &nbsp;component=&quot;.utils.landVocabulary&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;name=&quot;landVocabulary&quot;<br> &nbsp; &nbsp; &nbsp; &nbsp;/&gt;<br><br>Now I can use this vocabulary from any interface.<br><br>Best regards,<br>Hermann<br></blockquote>
</div><div><br class="khtml-block-placeholder"></div>Hello Hermann!<div style="">Since the country names depend on the locale I don&#39;t want to save the countryname on my object, only the country code. Hence, my utility contains only country codes, [&#39;AD&#39;, &#39;AF&#39;, ...].
</div><div style=""><br style=""></div><div style="">If, in my DropdownWidget, I provide a vocabulary on the form [(&#39;AD&#39;, &#39;Andorra&#39;), (&#39;Af&#39;, &#39;Afghanistan&#39;), ...] instead of the one in my utility, the constraint will obviously fail when the form is submitted (&#39;AD&#39; does not equal (&#39;AD,&#39;Andorra)).
</div><div style=""><br style=""></div><div style="">In my case you can say that the countrynames are &quot;dynamic&quot; and merealy a UI thing, whereas in your app you are retrieving a constant list of countrynames, right?&nbsp;
</div><div style="">Perhaps this should remove any misunderstandings you might have about my earlier post. (This problem _can_ be solved with z3c.widget but it&#39;d be nice to get this working on my own)</div><div style="">
<br style=""></div><div style="">My current solution is a quick hack: I save a list in DropdownWidget.territories on the form&nbsp;[(&#39;AD&#39;, &#39;Andorra&#39;), (&#39;Af&#39;, &#39;Afghanistan&#39;), ...] and then tal:repeat over it setting the &lt;option&gt;-value attribute to countrycode and put countryname inside &lt;option&gt;..&lt;/option&gt;.
</div><div style=""><br style=""></div><div style="">Regards</div><span class="sg"><div style=""><font class="Apple-style-span" color="#888888">/Jesper</font></div></span><br>