[Zope3-Users] Selectwidgets (Object is of wrong type)

Leonardo Rochael leo at enfoldsystems.com
Tue Oct 2 21:14:44 EDT 2007


You are probably experiencing a ValidationError in the .validate() method of
your "language" field. This is probably because TextLine expect the values
to be unicode whereas the vocabulary in your widget has (8-bit) string
values ("voc = SimpleVocabulary.fromItems([('de','German'), 
('en','English')])".


Maken Seteva wrote:
> 
> Hi!
> I'm having serious problems with getting a selectwidget/ 
> dropdownwidget working..
> What I want to do is to add a widget for the language field of a  
> MessageCatalog.
> Btw, a snippet from the interface (in zope.app.i18n.messagecatalog):
> 
>   class IMessageCatalog(Interface):
> #...
>           language = TextLine(
>           title=u"Language",
>           description=u"The language the catalog translates to.",
>           required=True)
> #...
> 
> 
> I already have an add view working but instead of manually filling in  
> 'en' for english,
> 'de' for german, etc. I now have a widget that generates this:
> 
> <select>
> <option value="en">English</option>
> <option value="de">German</option>
> <option ...etc
> 
> 
> But the thing is, I keep getting "Language: Object is of wrong  
> type."  displayed to me
> when I click the add button (i.e no system error). Here's the code:
> 
> -------------------------------------
>   class MessageCatalogAddForm(AddForm):
>       form_fields = Fields(IMessageCatalog)
>       label = _(u'Add message catalog')
>       form_fields['language'].custom_widget = LanguageDropDown
> 
>       def create(self, data):
>           msgcat = MessageCatalog(data['language'], data['domain'])
>           return msgcat
> 
> -------------------------------------
> class LanguageDropDown(DropdownWidget):
> 
>       def __init__(self, field, request):
> 	# Simple test to begin with, will use locale when i get this working..
>           voc = SimpleVocabulary.fromItems([('de','German'),  
> ('en','English')])
>           super(LanguageDropDown, self).__init__(field, voc, request)
> 
>       # Display the readable version, German & English instead of de  
> & en
>       def textForValue(self, term):
>           return term.value
> 
> 
> -----------------------------------------
> 
> I think I'm missing something or doing something wrong in  
> LanguageDropdown.__init__
> 
> Where does the constraint get checked for this Widget? I keep getting  
> "Object is of wrong type" but i can't
> find in what function this is generated.
> 
> 

-- 
View this message in context: http://www.nabble.com/Selectwidgets-%28Object-is-of-wrong-type%29-tf4557862.html#a13011336
Sent from the Zope3 - users mailing list archive at Nabble.com.



More information about the Zope3-users mailing list