Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Adds syntax for textareas
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed May 13, 2015
1 parent f2df788 commit 7d017af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
23 changes: 22 additions & 1 deletion onegov/form/parser/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ def textfield():
return textfield


def textarea():
""" Returns a textarea parser.
Example:
...[100*4]
"""

rows = Optional(Suppress('*') + numeric)('rows').setParseAction(as_int)
cols = numeric('cols').setParseAction(as_int)

dimension = Suppress('[') + cols + rows + Suppress(']')

textarea = Literal('...') + Optional(dimension)
textarea = textarea.setParseAction(tag(type='textarea'))

return textarea


def password():
""" Returns a password field parser.
Expand Down Expand Up @@ -196,7 +216,8 @@ def fieldset_title():
radio_buttons() |
checkboxes() |
select() |
password()
password() |
textarea()
)

field = field_declaration() + fields.setResultsName('field')
Expand Down
18 changes: 18 additions & 0 deletions onegov/form/tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ def test_textfield():
assert f.field.length == 25


def test_textarea():

f = field.parseString("Comment* = ...")
assert f.label == "Comment"
assert f.required
assert f.field.type == 'textarea'
assert f.field.cols == ''
assert f.field.rows == ''

f = field.parseString("Comment* = ...[25]")
assert f.field.cols == 25
assert f.field.rows == ''

f = field.parseString("Comment* = ...[1*2]")
assert f.field.cols == 1
assert f.field.rows == 2


def test_password():

f = field.parseString("Passwort* = ***")
Expand Down

0 comments on commit 7d017af

Please sign in to comment.