Tipfy wtform fields always render as input type="text"
I cant find examples of templates that use tipfy forms (extended wtforms). For example, If I want to implement birth date I want the "right" html for the user to enter his date of birth. Lets go with an example:
this is my form
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])
at the template :
<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>
however, the field for the form.birth_date render as html input tag with type="text". Do I have to override the call or html method? I want to get render the s开发者_C百科elect tag with options, so the user selects day/month/year and not by tipping it. I dont want the user to type a date in a text field
If I want html5 tags, I must override?
I am doing something wrong?
Thanks!
For the moment I resolved this using form macros
I had to use the 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])
this is the new template
<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>
精彩评论