When I use
{{form.Description}}
in my input form( template)
the field is not as large as I would need.
When I check HTML I can see
<textarea id="id_Description" class="vLargeTextField required"
name="Description" rows="10" cols="40"></textarea>
But I would need at least rows="20" cols="70".
Is there a way how to change the size from Django directly and not by
editing HTML code?
Thank you
L.B.
Hi Pythoni!
have you tried to take a look at oldforms/__init__.py file? There, look for the LargeTextField class and it's render function. I understand it's not exactily what you wanted, but it's a point to start ;)
good luck!
Tkm
Using newforms, yes:
Pass in an 'attrs' argument to the Textarea widget. e.g.,
class MyForm(forms.Form):
text = fields.TextField(widget=widgets.Textarea(attrs={'cols':'70',
'rows':'20'}))
This defines a text field that will use a Textarea widget to render;
by default, Textarea uses 1 40x10 area, but this can be overridden.
if you want to get really fancy, you can define your own subclass of
Textarea that hard codes your preferred sizes, and then request that
the TextField you the new widget :
class MyTextarea(widgets.Textarea):
def __init__(self, attrs={}):
attrs.update({'cols':'70', 'rows':'20'})
super(MyTextarea, self).__init__(attrs)
class MyForm(forms.Form):
text = fields.TextField(widget=widgets.MyTextarea)
(Note - I haven't run this code so it might have a syntax error or
two, but it should be enough to give you an idea and get you on the
way).
Yours,
Russ Magee %-)
with newforms is very simple.
you create the form from the model, like
ContactForm = forms.models.form_for_model(Contact)
and then you can change the atttribute:
ContactForm.base_fields ["name"].widget.attrs ["size"] = "50"
or
ContactForm.base_fields ["message"].widget.attrs ["rows"] = "10"
ContactForm.base_fields ["message"].widget.attrs ["cols"] = "50"
please tell me if it's the solution for your problem.
--
Alessandro Ronchi
Skype: aronchi - Wengo: aleronchi
http://www.alessandroronchi.net - Il mio sito personale
http://www.soasi.com - Sviluppo Software e Sistemi Open Source
On May 5, 4:27 am, Alessandro Ronchi <alessandro.ron...@gmail.com>
wrote:
> Alle venerdì 04 maggio 2007, Pythoni ha scritto:
>
> > But I would need at least rows="20" cols="70".
> > Is there a way how to change the size from Django directly and not by
> > editing HTML code?
> > Thank you
> > L.B.
>
> with newforms is very simple.
> you create the form from the model, like
> ContactForm = forms.models.form_for_model(Contact)
>
> and then you can change the atttribute:
> ContactForm.base_fields ["name"].widget.attrs ["size"] = "50"
>
> or
>
> ContactForm.base_fields ["message"].widget.attrs ["rows"] = "10"
> ContactForm.base_fields ["message"].widget.attrs ["cols"] = "50"
>
> please tell me if it's the solution for your problem.
> --
> Alessandro Ronchi
Thank you ALL who replied to help me solve the problem.
Unfortunately my program still uses 0.91 Django version so I do not
think I can use newforms.
Would be there any solution with oldforms? Or would you recommend to
add, to the form, HTML code of text area like this:
<textarea id="id_Description" class="vLargeTextField required"
name="Description" rows="20" cols="70"></textarea>
?
(That code is generated by Django)
But then I do not know how easy it would be to fill in the input text
area with the data to be edited.
Any idea would be appreciated
L.
I copy to 'myproject/templates/admin/base_site.html' the template from
the Django source tree: 'django/contrib/admin/templates/admin/
base_site.html', so I can overwrite it without patching Django.
Then I add something like
{% block extrastyle %}
<style type="text/css">
textarea#id_Description { width: 60em; height: 35em; }
</style>
{% endblock %}
That's enough for me, and works with oldforms.