TextInput module
This commit is contained in:
parent
0cffa63b5d
commit
a315aef576
@ -1,4 +1,6 @@
|
|||||||
from tornado.web import UIModule
|
from tornado.web import UIModule
|
||||||
|
# from tornado.template import raw
|
||||||
|
import re
|
||||||
|
|
||||||
class Alert(UIModule):
|
class Alert(UIModule):
|
||||||
def render(self, title, message=None, actions=None, level='info'):
|
def render(self, title, message=None, actions=None, level='info'):
|
||||||
@ -9,6 +11,16 @@ class Alert(UIModule):
|
|||||||
actions=actions,
|
actions=actions,
|
||||||
level=level)
|
level=level)
|
||||||
|
|
||||||
|
class TextInput(UIModule):
|
||||||
|
def render(self, input, placeholder=''):
|
||||||
|
return self.render_string(
|
||||||
|
"components/text_input.html.to",
|
||||||
|
input=input,
|
||||||
|
label=re.sub('<[^<]+?>', '', str(input.label)),
|
||||||
|
errors=input.errors,
|
||||||
|
placeholder=placeholder,
|
||||||
|
description=input.description)
|
||||||
|
|
||||||
class Icon(UIModule):
|
class Icon(UIModule):
|
||||||
def render(self, name, classes=''):
|
def render(self, name, classes=''):
|
||||||
with open('static/icons/%s.svg' % name) as svg:
|
with open('static/icons/%s.svg' % name) as svg:
|
||||||
|
21
templates/components/text_input.html.to
Normal file
21
templates/components/text_input.html.to
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<div class='usa-input {% if errors %}usa-input--error{% end %}'>
|
||||||
|
<label for={{input.name}}>
|
||||||
|
{{ label }}
|
||||||
|
|
||||||
|
{% if description %}
|
||||||
|
<span class='usa-input__help'>{% raw description %}</span>
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% if errors %}
|
||||||
|
{% module Icon('alert') %}
|
||||||
|
{% end %}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{% raw input(placeholder=placeholder) %}
|
||||||
|
|
||||||
|
{% if errors %}
|
||||||
|
{% for error in errors %}
|
||||||
|
<span class='usa-input__message'>{{ error }}</span>
|
||||||
|
{% end %}
|
||||||
|
{% end %}
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user