[Zope3-Users] providing IInputWidget using zope:view?

Garrett Smith garrett at mojave-corp.com
Thu Jun 2 17:38:20 EDT 2005


Oops...I see the example you list for your own code looks correct.

Here are some issues to consider for troubleshooting your problem:

- Are you getting an error when one of your fields shows up in an edit
form? If so, your first clue will be to look at the error message ;)

- If not (assuming this is the case) what widget is being used for your
field? If Zope is picking out the wrong widget, your field object either
doesn't implement the new field interface (IMyField) or the interface
resolution order is listing another interface first.

Here's a trick:

  >>> field = MyField()
  >>> from zope.interface import providedBy
  >>> providedBy(field).__iro__

This will print the list of interfaces in the order Zope uses for
lookup. It may be the case that IMyField shows up *after* some others,
which would cause Zope to find another widget.

 -- Garrett

Garrett Smith wrote:
> Tale a look at:
> 
>   src/zope/app/form/browser/configure.zcml
> 
> This is where the Zope widgets are registered for various field types.
> E.g. here's a registration that provides IInputWidget for ITextLine
> fields via the TextWidget class.
> 
>   <view
>       type="zope.publisher.interfaces.browser.IBrowserRequest"
>       for="zope.schema.interfaces.ITextLine"
>       provides="zope.app.form.interfaces.IInputWidget"
>       factory=".TextWidget"
>       permission="zope.Public"
>       />
> 
>  -- Garrett
> 
> Dylan Reinhardt wrote:
>> So I've got some custom fields and custom widgets.  Everything works
>> fine if I use the widget subdirective to editform to ensure that the
>> correct widget is paired with each field.
>> 
>> For how many times I'm going to re-use certain field/widget pairs, I
>> would like to associate a custom input widget with a specific field
>> interface so that *any* time that field is rendered in an editform,
>> the proper widget is used. 
>> 
>> Obviously, that's not a new idea... there's an example in Stephan
>> Richter's book.  He suggests something like this:
>> 
>> ----
>> <zope:view
>>      type="zope.publisher.interfaces.browser.IBrowserRequest"
>>      for=".interfaces.IMyField"
>>      provides="zope.app.form.interfaces.IInputWidget"
>>      factory=".widgets.MyWidget"
>>      permission="zope.Public"
>>      />
>> ----
>> 
>> So far, I haven't managed to get this to work.  I've tried a number
>> of things, such as adding a name, using class instead of factory,
>> using browser:view instead of zope:view.  All with no joy.    It
>> doesn't give any errors, but it doesn't provide the intended widget
>> either. 
>> 
>> Can anyone spare a quick example or suggest what I'm not doing
>> correctly? 
>> 
>> Many thanks in advance,
>> 
>> Dylan
>> _______________________________________________
>> Zope3-users mailing list
>> Zope3-users at zope.org
>> http://mail.zope.org/mailman/listinfo/zope3-users
> 
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users



More information about the Zope3-users mailing list