[Zope3-dev] Re: Default value of fields

Garrett Smith garrett at mojave-corp.com
Wed Sep 24 10:47:17 EDT 2003


Bjorn Tillenius wrote:

> I think I found some errors in the widget code, but I'm not quite
> sure how to fix it. Could someone explain to me how things are
> supposed to work?
> 
> If I specify a field to have a default value and I use an add form,
> that default value should show up there, right? Well, it doesn't
> right now.
> 
> One thing that troubles me is that in the end of setUpWidget,
> widget.setRenderedValue is called if widget.hasInput is false (which
> it is). This results in widget._data to get set to None.
> 
> Then in BrowserWidget._showData, the default value is only returned
> if 'widget._data is widget._data_marker and not widget.hasInput()'. But
> since widget._data got set to None that condition will evaluate to False
> and widget._data gets returned.
> 
> What is widget._data_marker used for? I havn't found any documentation
> about it. 
> 
> Is 'not widget.hasInput()' really a sufficient condition on whether to
> call setRenderedValue or not? Since this will always be true when using
> an add form, 'widget._data is widget._data_marker' will always be false.

The widget framework still needs some work. The 'default' value support 
is not implemented as one would expect.

For the time being, you should be able to control the 'default' value by 
setting it in your object initializer.

Here's some background on the work on widgets:

   http://dev.zope.org/Zope3/WidgetsFormsSchemas

There are some changes in this proposal that are not currently implemented:

- #5 Add getRawData() and setRawData() to IWidget

- #9 Refactor the widget input error framework

- #11 - Refactor BrowserWidget's _showData

See the discussion at the end of the proposal for the feedback to date.

I'm currently trying to clear my plate so I can get around to finishing 
this work up. There a couple of items that aren't listed as formal 
to-dos that I think need to happen:

- Create a 'simple widget' class to server as a the base for most of the 
existing widgets. This would clean up the issues surrounding uses of 
_data, _showData, _missing, etc. with a well defined protected interface.

- Break up widget's row() method into separate pieces (e.g. label, 
widget, etc.) to give templates more layout flexibility.

This info might be a bit off target -- I know you're just trying to get 
default values working, but I figure the background info might be helpful.

  -- Garrett





More information about the Zope3-dev mailing list