Skip to content

Commit

Permalink
Button takes optional argument html
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Oct 26, 2009
1 parent f0d08b7 commit 57674bc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion web/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,24 @@ def get_value(self):
return self.checked

class Button(Input):
"""HTML Button.
>>> Button("save").render()
'<button id="save" name="save">save</button>'
>>> Button("action", value="save", html="<b>Save Changes</b>").render()
'<button id="action" value="save" name="action"><b>Save Changes</b></button>'
"""
def __init__(self, name, *validators, **attrs):
super(Button, self).__init__(name, *validators, **attrs)
self.description = ""

def render(self):
attrs = self.attrs.copy()
attrs['name'] = self.name
return '<button %s>%s</button>' % (attrs, self.description)
if self.value is not None:
attrs['value'] = self.value
html = attrs.pop('html', None) or net.websafe(self.name)
return '<button %s>%s</button>' % (attrs, html)

class Hidden(Input):
"""Hidden Input.
Expand Down

0 comments on commit 57674bc

Please sign in to comment.