[Zope3-dev] Schema, widget and form refactoring (was Re: [Zope3-checkins]CVS:Zope3/src/zope/schema- _bootstrapfields.py:1.19.2.1)

Shane Hathaway shane@zope.com
Wed, 23 Jul 2003 14:49:19 -0400


Garrett Smith wrote:
> andre wrote:
>=20
>>Garrett Smith a =E9crit:
>>After having read a little about utility.py and widget.py, and in the
>>state of my knowledge,
>>
>>- it seems to me that the expression missing_value is ambiguous.
>>   value_if_missing will be better (IMO).
>>- it seems necessary to have a clear definition of the words used.
>>   (missing, required, default, None, etc.)
>=20
>=20
> On that last point, there is general agreement :-)
>=20
> See   http://dev.zope.org/Zope3/WidgetsFormsSchemas for a set of workin=
g
> definitions.
>=20
> I'm interested in your feedback on these. Do you see any problems?
> Anything that's just plain confusing?

This thread interests me.  I don't have strong opinions on this subject,=20
but I have some thoughts that might help.

I would use the term "initial value" instead of "default value".  To me,=20
"default" infers that when no user input was provided, the field reverts=20
to the default value instead of the missing value, but I assume that's=20
not what you intended.

The word "required" might not mean the same thing to everyone when=20
applied to a text field.  I think most people assume required means at=20
least one non-whitespace character must be entered in the text box.=20
Therefore, a required text field can have either a missing value or a=20
nonempty string value.

So I think the discussion over missing values is limited to non-required=20
text fields with an empty value.  Is it better to represent an empty=20
value as a missing value or an empty string?  Well, look at it this way:=20
let's say some object has a text field with an empty string value.=20
Someone comes along and uses a form to modify that object.  The user=20
changes some other widget and clicks "Save Changes".  The form=20
interprets the still-empty text string as None and writes that to the=20
object.  Oops!  The value of the field has changed from an empty string=20
to None, even though the user didn't change that field.  The accidental=20
change might trigger something unintended, like reindexing or an extra=20
log entry.

The problem is that two values (an empty string or None) get rendered=20
the same way in the browser.  To simplify that situation, it seems to me=20
that a non-required text field should not use the concept of a missing=20
value.  A non-required text field will always have a string value, empty=20
or not.

Finally, I haven't looked at the way wizards work, but I hope it's=20
somewhat similar to a GUI library.  Expressing my thoughts by example,=20
here's the kind of sequence I would expect in a wizard interaction.

Request 1: User starts the wizard
   - Zope locates or creates the form for page 1
   - Zope asks the form to render itself to HTTP
   - The form renders its widgets, looking in the session for
     previously entered values (which it won't find)
Request 2: User submits page 1, clicking "Next"
   - Zope locates or creates the form for page 1
   - Zope asks the form to validate
   - The form gets the schema
   - The form looks over the HTTP request, validating only
     the fields present on the form
   - The form indicates success
   - Zope asks the form to store the field values in the session
   - The form stores the field values
   - Zope asks the browser to visit page 2
Request 3: Browser requests page 2
   - Zope locates or creates the form for page 2
   ... etc ...

The wizard is a form containing forms.  Forms know a lot about HTML and=20
HTTP.  The forms might draw from GUI-agnostic WidgetLayout objects.  At=20
the end of the wizard, you can validate against the entire schema.  Now,=20
is that how it works, or am I a little off?

Shane