我无法找到使用tipfy表单(扩展wtforms)的模板示例。 例如,如果我想实现出生日期,我希望用户输入“正确”的HTML以输入他的出生日期。让我们举个例子:
这是我的表格
class RegistrationForm(Form):
name = fields.TextField('Nombre',validators=[REQUIRED])
email = fields.TextField('Email', validators=[REQUIRED,VALID_EMAIL])
birth_date = fields.DateTimeField('Fecha Nacimiento',format='%d/%m/%y',validators=[REQUIRED])
password = fields.PasswordField('Password', validators=[REQUIRED])
password_confirm = fields.PasswordField('Confirm the password', validators=[REQUIRED])
在模板上:
<form method="post" action="{{ current_url }}" enctype="multipart/form-data" class="tipfy-form">
<ol>
<li>{{ form_field(form.name, class='medium') }} </li>
<li>{{ form_field(form.email, class='medium') }}</li>
<li>{{ form_field(form.password, class='medium') }}</li>
<li>{{ form_field(form.password_confirm, class='medium') }}</li>
<li>{{ form_field(form.birth_date, class='medium') }}</li>
</ol>
<fieldset class="submit">
<input type="submit" name="submit" value="{{ _('Register') }}" class="button_auth">
</fieldset>
</form>
但是, form.birth_date 的字段呈现为带有type =“text”的html输入标记。我是否必须覆盖调用或html方法?我想用选项渲染选择标记,因此用户选择日/月/年而不是通过小费。 我不希望用户在文本字段中输入日期
如果我想要html5标签,我必须覆盖?
我做错了什么?
谢谢!
答案 0 :(得分:2)
目前我使用表格宏解决了这个问题
我必须使用SelectField
DAYS = [(x,x) for x in range(1,31)]
MONTHS = [x for x in [('enero',1),('febrero',2),('marzo',3),('abril',4),('mayo',5),('julio',6),('junio',7),('agosto',8),('setiembre',9),('octubre',10),('noviembre',11),('diciembre',12)] ]
YEARS = [(x,x) for x in range(1905,2010)]
class RegistrationForm(Form):
name = fields.TextField('Nombre',validators=[REQUIRED])
surnames = fields.TextField('Apellidos',validators=[REQUIRED])
email = fields.TextField('Email', validators=[REQUIRED,VALID_EMAIL])
birth_date_day = fields.SelectField('Fecha Nacimiento',format='%d/%m/%y',validators=[REQUIRED])
password = fields.PasswordField('Password', validators=[REQUIRED])
password_confirm = fields.PasswordField('Confirm the password', validators=[REQUIRED])
这是新模板
<form method="post" action="{{ current_url }}" enctype="multipart/form-data" class="tipfy-form">
<ol>
<li>{{ form_field(form.name, class='medium') }} </li>
<li>{{ form_field(form.surnames, class='medium') }} </li>
<li>{{ form_field(form.email, class='medium') }}</li>
<li>{{ form_field(form.password, class='medium') }}</li>
<li>{{ form_field(form.password_confirm, class='medium') }}</li>
<li>{{ form_field(form.sex, class='medium') }}</li>
<li>{{ form_field(form.birth_date, class='medium') }}</li>
<li>{{ form_field(form.birth_month, class='medium') }}</li>
<li>{{ form_field(form.birth_year, class='medium') }}</li>
</ol>
<fieldset class="submit">
<input type="submit" name="submit" value="{{ _('Register') }}" class="button_auth">
</fieldset>
</form>