List Info

Thread: Customizing form.x widgets - how?




Customizing form.x widgets - how?
user name
2006-06-22 18:36:04
Is there a way to change the HTML attributes that are
rendered when we
use {{form.x}} widgets?  Or is writing a custom tag the best
way?

The use-case and problem I have is when using a generic view
and a
form; suppose my object being edited has a field called
"description".
I'd like to just use {{form.description}} in the template,
but the
default size (cols=, rows=) isn't what I want.  I can setup
my own
<textarea> tag to display in the size I want, but then
I have to use
the tag {{object.description}} within the textarea - which
is a problem
when the user submits with an error, and the template will
show an
error message, BUT not the new description which was
submitted, only
the old one from the database.

Any tips would be appreciated, especially if I'm missing
something
obvious, thanks.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Customizing form.x widgets - how?
user name
2006-06-23 19:33:06
On Jun 22, 2006, at 1:36 PM, odoniangmail.com wrote:
> The use-case and problem I have is when using a generic
view and a
> form; suppose my object being edited has a field called
"description".
> I'd like to just use {{form.description}} in the
template, but the
> default size (cols=, rows=) isn't what I want.  I can
setup my own
> <textarea> tag to display in the size I want, but
then I have to use
> the tag {{object.description}} within the textarea -
which is a  
> problem
> when the user submits with an error, and the template
will show an
> error message, BUT not the new description which was
submitted, only
> the old one from the database.

CSS is the easiest way to deal with this specific issue. 
Each Django  
form element gets an id attribute of ``id_FIELDNAME``, so a
CSS rule  
like::

	#id_description { width: 30em; height 10em; }

Should do it for you.

Jacob

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Customizing form.x widgets - how?
user name
2006-06-29 00:32:39
Thanks for the tip.

It may still be useful if we could get at the form field
value by
itself, perhaps with a syntax like
"form.description.value" or
form.variable.value.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )