1.8.4.2 web.form.field.typed -- Typed fields for use with web.form and web.database.object

This module provides fields to support the following data types:

Type Description
Char A character field taking strings of length 1
String A string field taking strings of up to 255 characters
Text A text field for storing large amounts of text (up to 16k characters)
Integer An integer field taking any integer that is a valid Python integer (but not long)
Float A float field taking Python float values
Date A date field. Takes values in the form of python datetime objects. Only stores days, months and years, any other information is trunkated. Dates from 0001-01-01 to 9999-12-31.
Time A time field. Takes values in the form of python datetime objects. Only stores hours, minutes and seconds, any other information is trunkated.
DateTime A datetime field. Takes values in the form of python datetime objects. Only stores days, months, years, hours, minutes and seconds, any other information is trunkated.

Note: These Field objects correspond to the fields used by the web.database module. There is a reason for this; the Column objects in the web.database.object module are each derived from a web.form.field.typed Field. This means that columns from a web.database.object.Row are also valid form fields. This is used in the web.database.object classes to automatically generate and validate forms which can be used seamlessly and easily submit and edit data in a database.

Each of the data types listed below has three types of field specified:

Free
Allows the user to specify any value
Select
Allows the user to choose one value from a number of values specified
CheckBoxGroup
Allows the user to choose more than one option

The typed field classes have the same interface as their basic equivalents except that:

1. The Select and CheckBoxGroup classes take lists of their respective data types rather than value, label pairs.

2. The fields return their repsective Python object (or list of objects) when their .value attribute is called.

All the fields can either take their respective data type or the value None as possible values for the field. The only complications are the web.form.field.typed.String, web.form.field.typed.Text and classweb.form.field.typed.Char objects.

If someone enters no information into a String field there is a choice of whether to treat this as a null string '' or a NULL value None. To specify which behaviour you would like the web.form.field.typed.String object accepts the parameter treatNullStringAsNone which takes a default value of True. The web.form.field.typed.Char and web.form.field.typed.Text fields also accept the treatNullStringAsNone parameter.

The web.form.field.typed.Integer field also takes the parameters min and max to specify the minimum and maximum values and the parameters minError and maxError to specify the errors to display if the values are outside the specified minimum and maximum.

One more complication is how to display None values in the web.form.field.typed.StringSelect and classweb.form.field.typed.CharSelect objects. If you choose the string 'None' to display it how do you distinguish None from 'None'? Any value you choose could be confused with another string. The solution is to set a string value to dispaly None that isn't another value in the options. You can set this using the displayNoneAs parameter. None values for the other Select fields are just displayed as ''.