Package lemon :: Package html :: Module fields
[show private | hide private]
[frames | no frames]

Module lemon.html.fields

HTML Fields

The idea is that you can create field values in a standard way and then
you derive a form from the form class to look and behave exactly as you want your form to
behave with your own validation, export, import functions etc. Use a class for each field in the form.

See the doc/examples/code/forms.py example and all will become transparently clear


Developer Ideas
===============

It doesn't matter what the fields do internally but they must expose the following interface:

TIP: It isn't really worth trying to maintain complex data types inside the classes because often the values
come back as strings and your class may expect integers, doing a conversion could lead to an error before the
validation is done and just cause problems. It works out easier just to get the string values from the fields,
maintain them as a list of values and then convert them in the valid() funciton where you can let the user know
if things go wrong. This means clever inheritance is nearly impossible but will proabably save you any hassle.

builderValue() is for other applications to get the final value.


New Ideas
---------

Internally the fields keep their values as string representations. These values are set ant retrieved using the 
set() and get() methods. Fields taking multiple values are kept as an array of strings.

An empty string is treated as a NULL value for single fields. An empty array is treated as NULL for multiple
fields.

The populate() method is used to retrieve information from a dictionary (such as a cgi.FieldStorage() and populate
the field with the appropriate string representation value using the set() method. This way fields don't have to 
have make sure that they submit their string representation when a user clicks submit.

The retrieve() method is used in derived classes to convert from the string representation to a representation
suitatble for the value being represented.

Derived Classes
---------------

Derived from the base classes should be fields with types. For example integer fields, multiple time fields, date
fields etc. These should implement the retrieve() method explained above and the populate() method should also
accept the value output by retrieve().

Attribute Access
----------------

All classes should have private member variables with get() and set() methods. Attribute access should then be
emulated by overriding the __getattr__ () methods. This leads to robust code and a simple interface between the 
variables exposed to the user and the actual variables required.

Classes
Button Custom Button.
CheckBox CheckBox Field.
CheckBoxGroup Check Box Group Field.
Date Date Field.
DateTime Time Field.
Field Abstract base class from which other fields are derived.
File File Input Field.
Hidden Hidden Field...
Input Text Input Field.
Integer  
Menu Select Field.
Password Password Field.
RadioGroup Radio Group Field.
Reset Reset Button.
Select Select Field.
Submit Submit Button.
TextArea TextArea Field.
Time Time Field.

Variable Summary
str __author__ = 'James Gardner <james@xecos.com>'
str __credits__ = 'Guido van Rossum, for an excellent progra...
str __date__ = '9th April 2003'
str __version__ = '0.1'

Variable Details

__author__

Type:
str
Value:
'James Gardner <james@xecos.com>'                                      

__credits__

Type:
str
Value:
'Guido van Rossum, for an excellent programming language.'             

__date__

Type:
str
Value:
'9th April 2003'                                                       

__version__

Type:
str
Value:
'0.1'                                                                  

Generated by Epydoc 2.0 on Mon Nov 10 15:08:27 2003 http://epydoc.sf.net