Skip to content

Commit

Permalink
Moved placeholder to InputField, added additional validation attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Jurman committed Mar 12, 2012
1 parent 042fa5d commit c96ae1f
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tw2/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,33 @@ class InputField(FormField):
type = twc.Variable('Type of input field',
default=twc.Required,
attribute=True)

value = twc.Param(attribute=True)

min = twc.Param('Minimum value for field',
attribute=True, default=None)
max = twc.Param('Maximum value for field',
attribute=True, default=None)

minlength = twc.Param('Minumim length of field',
attribute=True, default=None)
maxlength = twc.Param('Maximum length of field',
attribute=True, default=None)

required = twc.Param('Input field is required',
attribute=True, default=None)

placeholder = twc.Param('Placeholder text (HTML5 Only)',
attribute=True, default=None)

template = "tw2.forms.templates.input_field"

def prepare(self):
super(InputField, self).prepare()
self.safe_modify('attrs')
self.attrs['required'] = 'required' if self.required in [True, 'required'] else None
self.retuired=None

class PostlabeledInputField(InputField):
""" Inherits :class:`InputField`, but with a :attr:`text`
label that follows the input field """
Expand All @@ -42,14 +66,12 @@ class PostlabeledInputField(InputField):

class TextField(InputField):
size = twc.Param('Size of the field', default=None, attribute=True)
placeholder = twc.Param('Placeholder text (HTML5 Only)', attribute=True, default=None)
type = 'text'


class TextArea(FormField):
rows = twc.Param('Number of rows', default=None, attribute=True)
cols = twc.Param('Number of columns', default=None, attribute=True)
placeholder = twc.Param('Placeholder text (HTML5 Only)', attribute=True, default=None)
template = "tw2.forms.templates.textarea"


Expand Down

0 comments on commit c96ae1f

Please sign in to comment.