How do I make a TextArea box in a form bigger?

1,382 views
Skip to first unread message

Michael Lake

unread,
Mar 14, 2007, 2:32:46 AM3/14/07
to django...@googlegroups.com
Hi all

I'm having problems trying to understand how to customise an element in a form.
Im using a TextField and I want the TextArea element to be much bigger in size.
From reading I gather one uses widgets. I found this page but it's quite different
from the code in my model or view. http://www.djangosnippets.org/snippets/35/

I'm wanting something like <textarea name=="details" cols=60 rows=70></textarea>
The code below is a minimal example that displays something like this
+------------+
| |
Lots of text: +------------+

The textarea is about two lines high only. I want the text entry box to be much
bigger as it will be holding a full page of text including HTML tags.

MODELS

from django.db import models

class Contact(models.Model):
name = models.CharField(maxlength=500)
phone = models.CharField(maxlength=200)
details = models.TextField()

VIEWS

from contacts_tutorial.contacts.models import Contact
from django import newforms as forms
from django.shortcuts import render_to_response

def test(request):

ContactForm = forms.form_for_model(Contact)
form = ContactForm()

data = { 'request': request,
'form': form,
}

return render_to_response('test.html', data)

TEMPLATE

<form action='{{ request.path }}' method='POST'>
Lots of text: {{ form.details }}
<input type=submit name='submit' value='Submit'>
</form>


--
Michael Lake

Kenneth Gonsalves

unread,
Mar 14, 2007, 2:58:46 AM3/14/07
to django...@googlegroups.com

On 14-Mar-07, at 12:02 PM, Michael Lake wrote:

> The textarea is about two lines high only. I want the text entry
> box to be much
> bigger as it will be holding a full page of text including HTML tags.

widgets.TextArea(attrs={'rows':10,'cols':60}) for example

--

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/


mail....@gmail.com

unread,
Mar 14, 2007, 9:50:03 AM3/14/07
to Django users
Or give it an id or class and just set it in the CSS.

Michael Lake

unread,
Mar 16, 2007, 1:01:37 AM3/16/07
to django...@googlegroups.com
Hi all

>>On 14-Mar-07, at 12:02 PM, Michael Lake wrote:
>>>The textarea is about two lines high only. I want the text entry

>>>box to be much bigger as it will be holding a full page of text ...

Kenneth helped out and suggested this:


>>widgets.TextArea(attrs={'rows':10,'cols':60}) for example

Thanks, but I'm still not sure where to place the above code.
The below didn't work:


ContactForm = forms.form_for_model(Contact)
form = ContactForm()

form.widgets.TextArea(attrs={'rows':10,'cols':60})
I'm guessing as I'm confused :-)

Also bax...@gretschpages.com wrote:
> Or give it an id or class and just set it in the CSS.

That I did work out :-) The textarea element has an id and I was able to set
the CSS style sheet to be textarea#id_itsname {width:90ex; height:40ex}
which keeps the user interface stuff in the CSS.

So I have it working using CSS but not with widgets.

Thanks
Mike

Kenneth Gonsalves

unread,
Mar 16, 2007, 1:34:08 AM3/16/07
to django...@googlegroups.com

On 16-Mar-07, at 10:31 AM, Michael Lake wrote:

> Hi all
>
>>> On 14-Mar-07, at 12:02 PM, Michael Lake wrote:
>>>> The textarea is about two lines high only. I want the text entry
>>>> box to be much bigger as it will be holding a full page of text ...
>
> Kenneth helped out and suggested this:
>>> widgets.TextArea(attrs={'rows':10,'cols':60}) for example
>
> Thanks, but I'm still not sure where to place the above code.

i have this:
formula = forms.CharField(widget=forms.widgets.TextArea(attrs={'rows':
10,'cols':60}))

Reply all
Reply to author
Forward
0 new messages