我想使用 Flask 的“SubmitField”
<button type="submit" title="Save this form"><span>Save</span></button>
代替:
<input type="submit" title="Save this form" />
我在模板中打印出来:
{{ field(class=css_class, title=field.description, **kwargs) }}
我猜我必须以某种方式修改 SubmitInput(SubmitField 后面的小部件),但我不确定如何准确地做到这一点,我是否必须以某种方式修改 __html__()?
编辑:
from flask.ext.wtf import Required, Length, EqualTo, Field, TextInput
from flask import Markup
class InlineButtonWidget(object):
html = """
<button type="submit" title="%s"><span>%s</span></button>
"""
def __init__(self, input_type='submit'):
self.input_type = input_type
def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)
kwargs.setdefault('type', self.input_type)
if 'value' not in kwargs:
kwargs['value'] = field._value()
return HTMLString(self.html % (field.name, field.label ))
class InlineButton(Field):
widget = InlineButtonWidget()
def _value(self):
if self.data:
return u', '.join(self.data)
else:
return u''
class SignupForm(Form):
name = TextField('Name', [Length(min=1, max=200)])
submit = InlineButton('sign up')
我希望能够做到这一点:
submit = InlineButton({'name' : 'submit', 'title' : '今天注册有奖。', 'type' : 'submitfieldtype', 'textInsideSpan' : '保存当前工作' })