watson.form.fields¶
- class watson.form.fields.Button(name=None, value=None, label=None, label_attrs=None, **kwargs)[source]¶
Creates a button, can be used instead of Input(type=”button”).
- class watson.form.fields.Checkbox(name=None, values=None, value=None, **kwargs)[source]¶
Creates a checkbox input.
Example:
field = Checkbox(name='test', label='My Radio Options', values=(('Test', 1), ('Testing', 2))) str(field)
<fieldset> <legend>My Checkbox Options</legend> <label for="test_0">Test<input id="test_0" name="test" type="checkbox" /></label> <label for="test_1">Testing<input id="test_1" name="test" type="checkbox" /></label> </fieldset>
field = Checkbox(name='test', label='My Checkbox', values=1) str(field)=None
<label for="test"><input type="checkbox" name="test" value="1" />My Checkbox</label>
- __init__(name=None, values=None, value=None, **kwargs)[source]¶
Initializes the checkbox.
If a value is specified, then that value out of the available values will be checked. If multiple values are specified, then a checkbox group will be created.
Parameters: - name (string) – the name of the field
- values (tuple|list) – the values to be used
- value (mixed) – the value for the field
- class watson.form.fields.Csrf(name='csrf_token', value=None, **kwargs)[source]¶
Creates an <input type=”hidden” /> element for use in csrf protection.
- class watson.form.fields.Date(name=None, value=None, format='%Y-%m-%d', **kwargs)[source]¶
Creates an <input type=”date” /> element.
- class watson.form.fields.Email(name=None, value=None, **kwargs)[source]¶
Creates an <input type=”email” /> element.
- class watson.form.fields.FieldMixin(name=None, value=None, label=None, label_attrs=None, **kwargs)[source]¶
A mixin that can be used as a base to simplify the creation of fields.
- label¶
watson.form.fields.Label
the label associated with the field
- html¶
string
the html used to render the field
- validators¶
list
the validators that will be used to validate the value
- filters¶
list
the filters that will be used prior to validation
- __init__(name=None, value=None, label=None, label_attrs=None, **kwargs)[source]¶
Initializes the field with a specific name.
- filter()[source]¶
Filter the value on the field based on the associated filters.
Set the original_value of the field to the first value stored. Note, if this is called a second time, then the original value will be overridden.
- class watson.form.fields.GroupInputMixin(name=None, values=None, value=None, **kwargs)[source]¶
A mixin for form elements that are used in a group.
Related form elements are wrapped in a fieldset, with a common legend.
- class watson.form.fields.Hidden(name=None, value=None, **kwargs)[source]¶
Creates an <input type=”hidden” /> element.
- class watson.form.fields.Input(name=None, value=None, label=None, label_attrs=None, **kwargs)[source]¶
Creates an <input> field.
Custom input types can be created by sending type=’type’ through the __init__ method.
Example:
input = Input(type='text') # <input type="text" />
- class watson.form.fields.Label(text, **kwargs)[source]¶
A <label> tag which can be automatically included with fields.
- html¶
string
the html used to render the label
- text¶
string
the text associated with the label
- class watson.form.fields.Password(name=None, value=None, **kwargs)[source]¶
Creates an <input type=”password” /> element.
- class watson.form.fields.Radio(name=None, values=None, value=None, **kwargs)[source]¶
Creates a radio input.
Example:
field = Radio(name='test', label='My Radio Options', values=(('Test', 1), ('Testing', 2))) str(field)
<fieldset> <legend>My Radio Options</legend> <label for="test_0">Test<input id="test_0" name="test" type="radio" value="1" /></label> <label for="test_1">Testing<input id="test_1" name="test" type="radio" value="2" /></label> </fieldset>
field = Radio(name='test', label='My Radio', values=1) str(field)
<label for="test"><input type="radio" name="test" values="1" />My Radio</label>
- class watson.form.fields.Select(name=None, options=None, value=None, multiple=False, **kwargs)[source]¶
Creates a select field.
- html¶
string
the html for the outer select element
- option_html¶
string
the individual option html element
- optgroup_html¶
string
the optgroup html element
- options¶
list|dict
the options available
- __init__(name=None, options=None, value=None, multiple=False, **kwargs)[source]¶
Initializes the select field.
If the options passed through are a dict, and the value of each key is a list or tuple, then an optgroup will be rendered, using the key as the label for the optgroup.
Parameters: - name (string) – the name of the field
- options (list|dict) – the options available
- value (string) – the selected value
- multiple (bool) – whether or not to allow multiple selections
Example:
field = Select(name='test', options=collections.OrderedDict([('Group One', [1, 2]), ('Group Two', [1, 2])])) str(field)
<select name="test"> <opgroup label="Group One"> <option value="1">1</option> </optgroup> <opgroup label="Group Two"> <option value="2">2</option> </optgroup> </select>
- class watson.form.fields.Submit(name=None, value=None, button_mode=False, **kwargs)[source]¶
Creates a submit input.
bool
whether or not to render as <button> or <input>