Feature request: Textareas and classes for labels

12 views
Skip to first unread message

Voltron

unread,
Mar 2, 2012, 1:08:04 PM3/2/12
to Humongolus
Me again! If you've got the time, could you implement the Textarea tag
and allow CSS classes to be defined for labels? What about lables also
being first class widgets too?

Thanks

Christopher S Coté

unread,
Mar 5, 2012, 1:15:26 PM3/5/12
to humon...@googlegroups.com
I'll hopefully get to work on this tonight.

If you want to provide a Form model of how you would like to see labels
as widgets implemented that would be very helpful.

Also, you should very easily be able to add a textarea widget, and do a
pull request ;)

Christopher S Coté

unread,
Mar 5, 2012, 5:12:38 PM3/5/12
to humon...@googlegroups.com
TextArea widget has been committed.

Please give me an example of how you'd like to use the label widgets.


On 03/02/2012 12:08 PM, Voltron wrote:

Voltron

unread,
Mar 6, 2012, 12:56:56 PM3/6/12
to Humongolus
Great! I will test the textarea asap. Labels should allow more access,
take a look at this snippet I implemented using WTForms:


{% if field.type == "BooleanField" %} <label>{% raw
field.label.text %}</label>
{% raw field(title=_(field.description),
class_="pull-left", value="") %}
{% elif field.type == "TextAreaField" %}
{% raw field.label %}
{% raw field(title=_(field.description),
rows="2" ) %}
{% else %}
{% raw field.label %}
{% raw field(title=_(field.description)) %}
{% end %} <span id="{{field.id}}
_help">{{ _(field.description) }}</span>

One can access a fields label properties easier as in "<label>{% raw
field.label.text %}</label>"

I wonder if this would also be necessary, http://wtforms.simplecodes.com/docs/dev/fields.html,
take a look at the "rendering" part, the functions __cal__ and
__html__. As it is, WTForms is still a little more comfortable to use.
I would like to test a bit more to be sure though

Christopher Coté

unread,
Mar 7, 2012, 5:52:56 PM3/7/12
to humon...@googlegroups.com
I've updated the example app to show you how you would render a form in a similar manner that you're used too. see form.html

The issue with doing it that way, is for complex, heavily embedded documents, the namespace of the fields is very important for proper parsing/validating of the data.

if you run python app.py and go to localhost:8888 you should see 2 forms.

The top one is rendered using a loop, the bottom is rendered by calling the recursive render function on the form.

I handle my forms slightly differently, in that I just return any errors and render them using js, rather than returning the fully rendered html.

Both should work just fine.

Christopher Coté

unread,
Mar 7, 2012, 5:53:48 PM3/7/12
to humon...@googlegroups.com
here's the form.html for reference.

{% import humongolus.field as o_field %}
{% import humongolus.widget as widget %}
<form action="{{ form.attributes.action }}" method="{{ form.attributes.method }}">
{% for field in form %}
{% if isinstance(field.object, o_field.Boolean) %}
<label class='woot'>{{ field.attributes.label }}</label>
{% else %}
<label>{{ field.attributes.label }}</label>
{% end %}
{% if field.attributes.name in form.errors %}
<span class='error'>{{ form.errors[field.attributes.name] }}</span>
{% end %}
{% raw field() %}
{% end %}
<input type='submit' value='save me!'/>
</form>

Voltron

unread,
Mar 8, 2012, 2:51:05 AM3/8/12
to Humongolus
I also meant to say that one can render the label tag easier,
independently using WT

{% else %}
{% raw field.label %} <-- renders complete label tag
Reply all
Reply to author
Forward
0 new messages