sprox.mootools.formbase

Mootools Formbase Module

Classes to create Mootools forms (client side validation!)

Copyright (c) 2008 Christopher Perkins Original Version by Christopher Perkins 2008 Released under MIT license.

Classes

class sprox.mootools.formbase.MootoolsFormBase(provider_hint=None, **provider_hints)

Bases: sprox.formbase.FormBase

FormBase for Mootools

see sprox.formbase.FormBase

validate(params, state=None, use_request_local=True)

A pass-thru to the widget’s validate function.

class sprox.mootools.formbase.MootoolsEditableForm(provider_hint=None, **provider_hints)

Bases: sprox.formbase.EditableForm

validate(params, state=None, use_request_local=True)

A pass-thru to the widget’s validate function.

class sprox.mootools.formbase.MootoolsTableForm(*args, **kw)

Bases: tw.forms.fields.TableForm, tw.mootools.forms.CustomisedForm

action = ''
action__doc = "The url where the form's contents should be submitted"
adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

attrs = {}
attrs__doc = 'Extra attributes for the outermost DOM node'
available_engines = ['mako', 'genshi']
blank_deleted = True
blank_deleted__doc = 'Blank out any deleted form fields from GrowingTable on the page. This is required for growing to function correctly - you must use GrowingTableFieldSet within a CustomisedForm with this option set.'
children_deep
clone(*args, **kw)
container_attrs = {}
container_attrs__doc = 'Extra attributes to include in the container tag around this widget'
css = [CSSLink(None, children=[], **{'modname': 'tw.mootools.forms', 'javascript': [], 'filename': 'static/formcheck/theme/classic/formcheck.css'})]
css_class__doc = 'Main CSS class for this widget'
css_classes = []
css_classes__doc = 'A list with extra css classes for the widget.'
default = None
disable_enter = True
disable_enter__doc = 'Disable the enter button (except with textarea fields). This reduces the chance of users accidentally submitting the form.'
disabled = None
disabled__doc = "Should the field be disbaled on render and it's input ignored by the validator? UNIMPLEMENTED"
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

engine_name = 'genshi'
error_at_request

Validation error for current request.

file_upload = False
force_conversion = False
form_lang = 'en'
generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.

help_text = None
help_text__doc = 'Description of the field to aid the user'
hover_help = False
id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id__doc = 'The id of this widget. This id is used to reference a widget from its parent ``children`` attribute and is usually the DOM id of outermost HTML tag of the widget.'
id_path_elem
ifields
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
ihidden_fields
is_required
is_required__doc = 'Computed flag indicating if input is required from this field'
is_root

True if the widget doesn’t have a parent

javascript = [MootoolsCoreLink(None, children=[], **{'suffix': 'yc'}), MootoolsMoreLink(None, children=[], **{'suffix': 'yc'}), JSLink(None, children=[], **{'modname': 'tw.mootools.forms', 'javascript': [], 'filename': 'static/formcheck/formcheck.js'}), JSLink(None, children=[], **{'modname': 'tw.mootools.forms', 'javascript': [], 'filename': 'static/forms.js'})]
key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
label_text = None
label_text__doc = 'The text that should label this field'
method = 'post'
method__doc = 'The HTTP request method to be used'
name
name__doc = 'Name for this input Widget. This is the name of the variable that will reach the controller. This parameter can only be set during widget initialization'
name_path_elem
params = frozenset(['label_text', 'suppress_label', 'strip_name', 'show_children_errors', 'disabled', 'attrs', 'container_attrs', 'help_text', 'id', 'show_labels', 'submit_text', 'style', 'hover_help', 'name', 'table_attrs', 'css_class', 'disable_enter', 'blank_deleted', 'show_error', 'css_classes', 'action', 'is_required', 'method', 'validate_inputs'])
parent = None
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)
prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

show_children_errors = True
show_error = False
show_error__doc = "Should the field display it's own errors? Defaults to False because normally they're displayed by the container widget"
show_labels = True
source_vars = frozenset([])
strip_name = False
strip_name__doc = "If this flag is True then the name of this widget will not be included in the fully-qualified names of the widgets in this subtree. This is useful to 'flatten-out' nested structures. This parameter can only be set during initialization."
style = None
style__doc = "Style properties for the field. It's recommended to use css classes and stylesheets instead of this parameter"
submit_label__doc = 'Label text for the auto-generated submit button. If empty then no label will be generated.'
submit_label_text = ''
submit_text = 'Submit'
submit_text__doc = 'Text that should appear in the auto-generated Submit button. If None then no submit button will be autogenerated.'
suppress_label = False
suppress_label__doc = 'Allows individual widgets to suppress the attached label in their container'
table_attrs = {}
template = 'tw.forms.templates.table_form'
update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

<foo bar='$bar' zoo='$zoo' />

Do:

<foo py:attrs="attrs" />

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(params)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

validate_inputs = True
validate_inputs__doc = 'When the user clicks the submit button, verify that all required fields are entered'
validator

alias of DefaultValidator

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''

Discuss

blog comments powered by Disqus

Table Of Contents

Previous topic

sprox.dojo.formbase

Next topic

test_model

This Page