Skip to content

Commit

Permalink
Added text and password widget HTML5 attributes required by plone.login.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbcunc committed Mar 18, 2014
1 parent 55b92d4 commit f4e85b7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHOR.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ Michael Howitz
Michael Kerrin
Paul Carduner
Dylan Jay
Chris Calloway
3 changes: 1 addition & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ CHANGES
3.1.2 (unreleased)
------------------

- Nothing changed yet.

- Added text and password widget HTML5 attributes required by plone.login.

3.1.1 (2014-03-02)
------------------
Expand Down
14 changes: 14 additions & 0 deletions src/z3c/form/browser/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ class IHTMLTextInputWidget(IHTMLFormElement):
u'characters the user may enter.'),
required=False)

placeholder = zope.schema.TextLine(
title=u'Placeholder Text',
description=(u'This attribute represents a short hint '
u'(a word or short phrase) intended to aid the user '
u'with data entry when the control has no value.'),
required=False)

autocapitalize = zope.schema.Choice(
title=u'Auto-Capitalization Control',
description=(u'This attribute controls whether the browser should '
u'automatically capitalize the input value.'),
values=('off', 'on'),
required=False)


class IHTMLTextAreaWidget(IHTMLFormElement):
"""A widget using the HTML TEXTAREA element."""
Expand Down
11 changes: 11 additions & 0 deletions src/z3c/form/browser/password.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ reasons:
<input type="password" id="widget.id" name="widget.name"
class="password-widget" />

Adding some more attributes to the widget will make it display more:

>>> widget.style = u'color: blue'
>>> widget.placeholder = u'Confirm password'
>>> widget.autocapitalize = u'off'

>>> print(widget.render())
<input type="password" id="widget.id" name="widget.name"
placeholder="Confirm password" autocapitalize="off"
style="color: blue" class="password-widget" />

Let's now make sure that we can extract user entered data from a widget:

>>> widget.request = TestRequest(form={'widget.name': 'password'})
Expand Down
4 changes: 3 additions & 1 deletion src/z3c/form/browser/password_input.pt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
accesskey view/accesskey;
onselect view/onselect;
size view/size;
maxlength view/maxlength" />
maxlength view/maxlength;
placeholder view/placeholder;
autocapitalize view/autocapitalize;" />
</html>
3 changes: 3 additions & 0 deletions src/z3c/form/browser/text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ Adding some more attributes to the widget will make it display more:
>>> widget.name = 'name'
>>> widget.value = u'value'
>>> widget.style = u'color: blue'
>>> widget.placeholder = u'Email address'
>>> widget.autocapitalize = u'off'

>>> print(widget.render())
<input type="text" id="id" name="name" class="text-widget"
placeholder="Email address" autocapitalize="off"
style="color: blue" value="value" />


Expand Down
4 changes: 3 additions & 1 deletion src/z3c/form/browser/text_input.pt
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
accesskey view/accesskey;
onselect view/onselect;
size view/size;
maxlength view/maxlength" />
maxlength view/maxlength;
placeholder view/placeholder;
autocapitalize view/autocapitalize;" />
</html>
2 changes: 2 additions & 0 deletions src/z3c/form/browser/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ class HTMLTextInputWidget(HTMLInputWidget):

size = FieldProperty(interfaces.IHTMLTextInputWidget['size'])
maxlength = FieldProperty(interfaces.IHTMLTextInputWidget['maxlength'])
placeholder = FieldProperty(interfaces.IHTMLTextInputWidget['placeholder'])
autocapitalize = FieldProperty(interfaces.IHTMLTextInputWidget['autocapitalize'])


@zope.interface.implementer(interfaces.IHTMLTextAreaWidget)
Expand Down

0 comments on commit f4e85b7

Please sign in to comment.