Skip to content

Commit

Permalink
Added a text_attrs Param to PostlabeledInputField (please check the a…
Browse files Browse the repository at this point in the history
…pplicable Genshi template for errors - I don't know if py:attrs erases other attributes). Also added PostlabeledCheckBox, which is just a double inheritance with a pass.
  • Loading branch information
chbrown committed Dec 16, 2009
1 parent 7e5f720 commit 2e1f072
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion tw2/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
This package contains the basic form widgets.
"""

from widgets import (Button, CheckBox, FieldSet, FileField, Form, HiddenField, ImageButton,
from widgets import (Button, CheckBox, PostlabeledCheckBox,
FieldSet, FileField, Form, HiddenField, ImageButton,
Label, Spacer, ListLayout, TableLayout, PasswordField,
RadioButton, ResetButton, SubmitButton, TextField, TextArea,
SingleSelectField, MultipleSelectField, RadioButtonList, CheckBoxList,
Expand Down
2 changes: 1 addition & 1 deletion tw2/forms/templates/postlabeled_input_field.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<input xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs"/> <label for='${w.compound_id}'>$w.text</label>
<input xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs"/> <label for='${w.compound_id}' py:attrs="w.text_attrs">$w.text</label>
2 changes: 1 addition & 1 deletion tw2/forms/templates/postlabeled_input_field.mak
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<%namespace name="tw" module="tw2.core.mako_util"/>\
<input ${tw.attrs(attrs=w.attrs)}/> <label for='${w.compound_id}'>${w.text}</label>
<input ${tw.attrs(attrs=w.attrs)}/> <label for='${w.compound_id}' ${tw.attrs(attrs=w.text_attrs)}>${w.text}</label>
7 changes: 5 additions & 2 deletions tw2/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class InputField(FormField):

class PostlabeledInputField(InputField):
"""Inherits :class:`InputField`, but with a :attr:`text` label that follows the input field"""
text = twc.Param('Text to display after the field')
text = twc.Param('Text to display after the field.')
text_attrs = twc.Param('Dict of attributes to inject into the label.', default={})
template = "tw2.forms.templates.postlabeled_input_field"


Expand All @@ -38,7 +39,9 @@ def prepare(self):
self.safe_modify('attrs')
self.attrs['checked'] = self.value and 'checked' or None
self.value = None


class PostlabeledCheckBox(CheckBox, PostlabeledInputField):
pass

class RadioButton(InputField):
type = "radio"
Expand Down

0 comments on commit 2e1f072

Please sign in to comment.