widget=forms.HiddenInput doesn't work

185 views
Skip to first unread message

rizzoo

unread,
Apr 1, 2009, 9:16:43 PM4/1/09
to Django users
How do I make a field hidden when using ModelForm? I tried
HiddenInput but it appears to be ignored.

code: http://dpaste.com/22290/
Line 9

Here's what View Source shows for that line in the browners:
<label for="id_last">Last:</label><input id="id_last" type="text"
name="last" maxlength="45"


When I use "widget=forms.HiddenInput()" i don't get any errors but it
doesn't hide the field. The field still shows as type="text" rather
than type="hidden"

Line 9 doesn't seem to do anything. It still displays the field as
"text" instead of "hidden".

You can see other attempts that are commented out that also don't
work. What am I doing wrong?
Thanks in advanced

rizzoo

Brian Neal

unread,
Apr 1, 2009, 9:53:13 PM4/1/09
to Django users
On Apr 1, 8:16 pm, rizzoo <michaelros...@gmail.com> wrote:
> How do I make a field hidden when using ModelForm?  I tried
> HiddenInput but it appears to be ignored.
>
> code:http://dpaste.com/22290/
> Line 9
>
> Here's what View Source shows for that line in the browners:
> <label for="id_last">Last:</label><input id="id_last" type="text"
> name="last" maxlength="45"
>

Well it looks like you are trying to hide the field "name". So why are
you showing us the HTML for the field named "last"?

I just did this the other day and it worked for me.

Can you post your model code too?

BN

Michael Rose Jr.

unread,
Apr 1, 2009, 11:19:38 PM4/1/09
to Django users
Brian. Thanks for responding. I mean to post "name". I've been
experimenting with other field types, which why I accidentally pasted
"last". Here is the HTML for "name".
<label for="id_name">Name:</label></th><td><input id="id_name"
type="text" name="name" maxlength="45" />

Here's the model. http://dpaste.com/22453/
Thanks again for your help.

Riz

Brian Neal

unread,
Apr 1, 2009, 11:38:58 PM4/1/09
to Django users
On Apr 1, 10:19 pm, "Michael Rose Jr." <michaelros...@gmail.com>
wrote:
>
> Brian. Thanks for responding. I mean to post "name". I've been
> experimenting with other field types, which why I accidentally pasted
> "last". Here is the HTML for "name".
> <label for="id_name">Name:</label></th><td><input id="id_name"
> type="text" name="name" maxlength="45" />
>
> Here's the model.http://dpaste.com/22453/
> Thanks again for your help.
>
> Riz

Hmmm, I don't see anything obviously wrong. I just did something like
this myself with a model form and it worked fine for me.

What version of Django are you using? And sorry to have to ask this,
but are you using the development server? (Just ruling out that the
code is getting reloaded after you make changes.)

BN

Brian Neal

unread,
Apr 1, 2009, 11:40:15 PM4/1/09
to Django users
On Apr 1, 10:19 pm, "Michael Rose Jr." <michaelros...@gmail.com>
wrote:
>
> Brian. Thanks for responding. I mean to post "name". I've been
> experimenting with other field types, which why I accidentally pasted
> "last". Here is the HTML for "name".
> <label for="id_name">Name:</label></th><td><input id="id_name"
> type="text" name="name" maxlength="45" />
>
> Here's the model.http://dpaste.com/22453/
> Thanks again for your help.
>
> Riz

Oh, one more thing. How are you displaying your form in your template?
Can you post that part of your template?

BN

Michael Rose Jr.

unread,
Apr 1, 2009, 11:57:05 PM4/1/09
to Django users
Hi Brian,

Here's the template:
http://dpaste.com/22457/

Here's the "view source" (Line 5)
http://dpaste.com/22458/

I am seeing this issue in the development server and in production/
Apache. I restarted both and cleared my cache in my browsers just to
be sure that wasn't the issue.

Python 2.5.2 (r252:60911, Jan 4 2009, 21:59:32)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 0, 2, 'final', 0)
>>>

Thanks,

Riz

Michael Rose Jr.

unread,
Apr 2, 2009, 8:33:27 PM4/2/09
to Django users
This was fixed by upgrading to the latest version in SVN.

Thanks for your help B

On Apr 1, 8:57 pm, "Michael Rose Jr." <michaelros...@gmail.com> wrote:
> On Apr 1, 8:40 pm, Brian Neal <bgn...@gmail.com> wrote:
>
>
>
> > On Apr 1, 10:19 pm, "Michael Rose Jr." <michaelros...@gmail.com>
> > wrote:
>
> > > Brian. Thanks for responding. I mean to post "name". I've been
> > > experimenting with other field types, which why I accidentally pasted
> > > "last". Here is the HTML for "name".
> > > <label for="id_name">Name:</label></th><td><input id="id_name"
> > > type="text" name="name" maxlength="45" />
>
> > > Here's the model.http://dpaste.com/22453/
> > > Thanks again for your help.
>
> > > Riz
>
> > Oh, one more thing. How are you displaying your form in your template?
> > Can you post that part of your template?
>
> > BN
>
> Hi Brian,
>
> Here's the template:http://dpaste.com/22457/
>
> Here's the "view source" (Line 5)http://dpaste.com/22458/
Reply all
Reply to author
Forward
0 new messages