Problem with rendered forms and values

14 views
Skip to first unread message

Voltron

unread,
Feb 29, 2012, 7:31:16 PM2/29/12
to Humongolus
I have been trying for a while to post a form using AJAX, I have no
idea what is going wrong because the values are never changed,
strangely, the default value is always posted

<input type="text" id="id_email" name="email" value="None">

The fields should look like this when rendered with a GET commande
with novalues:

<input type="text" id="id_email" name="email" /> # <- wth the slash
too

Christopher S Coté

unread,
Feb 29, 2012, 7:51:45 PM2/29/12
to humon...@googlegroups.com
Yeah, None should not populate, easy fix, give me a few hours to get to
it though.

Christopher Coté

unread,
Feb 29, 2012, 10:43:30 PM2/29/12
to humon...@googlegroups.com
just committed a fix for None values rendering, however I wasn't able to replicate the missing slash.

Voltron

unread,
Mar 1, 2012, 2:27:54 AM3/1/12
to Humongolus
Hi! I am still having problems, I will try to do some more digging to
find out why. For the mean time, a quick test showed this in my
template

<input type="text" id="id_email" name="email" value="None"
class="test_class"> # <- missing slash, prefilled value attribute
<input type="text" id="id_email" name="email" value="None" class=""> #
<- missing slash, empty class attribute should not show up

This field was rendered with this snippet

<form id="login-form" method="post" onSubmit="return
false">
{% for field in form %}
{% raw _(field.label()) %}

{% if field.errors %}
<ul>
{% for error in field.errors %}
<li>{% raw _(error) %}</li>
{% end %}
</
ul>
{% end %}
{% raw field.render(cls='test_class') %}
{% raw field.render()
%}
{% end %}
{% end %}
<button id="login-submit" type="submit">submit</
button>
</form>
Thanks!

Voltron

unread,
Mar 1, 2012, 2:36:33 AM3/1/12
to Humongolus
Another thing, rendering a field.description emmits a traceback
because the attribute is missing. It should be present and set to none
so that one can make a boolean test conditional render

Christopher S Coté

unread,
Mar 1, 2012, 12:07:54 PM3/1/12
to humon...@googlegroups.com
Are you using the latest version. I've fixed the description issue and
and None definitely doesn't render anymore.

I'll try using the email field to test the missing slash.

I'll try to get rid of the empty attributes as well.

Voltron

unread,
Mar 1, 2012, 12:33:49 PM3/1/12
to Humongolus
Something must have gotten mixed up. I downloaded it 3 times, same
results.

Christopher S Coté

unread,
Mar 1, 2012, 2:03:23 PM3/1/12
to humon...@googlegroups.com
Ok, big update for the widget system.

All widget attributes are available through the "attributes"
attribute... say that 5 times fast.

Also, empty attributes should not render at all.

I'm worried your somehow not getting the latest version of the files.

Are you doing a git pull/clone or are you using the download functionality?

Once you get the latest version, make sure there is an "escape" function
at the top of the widget.py module, that should ensure you have the latest.

You may also want to delete your .pyc files.


On 03/01/2012 11:33 AM, Voltron wrote:
> Something must have gotten mixed up. I downloaded it 3 times, same
> results.
>

Voltron

unread,
Mar 1, 2012, 2:19:25 PM3/1/12
to Humongolus
Great! I get the files by going to your repo on github and hitting
"download zip". I will check again

Voltron

unread,
Mar 1, 2012, 4:09:16 PM3/1/12
to Humongolus
Ok, everything else seems OK, but the value attribute is still being
prefilled. The only difference is that the value is now a list instead
of a single value:
arguments:  {'_xsrf': ['536a0ec21b30487286284ab39fd61dcb'],
'password': ['None'], 'email': ['None']}

Another test outside a tornado template:

<input name='email' value='None' id='id_email' type='text' />

Christopher S Coté

unread,
Mar 1, 2012, 4:14:37 PM3/1/12
to humon...@googlegroups.com
Ok, can you post a little more of your code.

I'm confused on what exactly your trying to do.

Your passing in arrays for the values, and strings of "None", this is
going to render those as such.

You should really use an object to pre-populate as it will convert the
strings to the proper types before populating.

When handling an incoming form submission you should be able to just
pass in a dictionary of your field names and their values, the values
should not be an array however.

Please post your code, thanks.

On 03/01/2012 03:09 PM, Voltron wrote:
> Ok, everything else seems OK, but the value attribute is still being
> prefilled. The only difference is that the value is now a list instead
> of a single value:
> arguments: {'_xsrf': ['536a0ec21b30487286284ab39fd61dcb'],
> 'password': ['None'], 'email': ['None']}
>
> Another test outside a tornado template:
>
> <input name='email' value='None' id='id_email' type='text' />
>
> On Mar 1, 8:19 pm, Voltron<nhy...@googlemail.com> wrote:
>> Great! I get the files by going to your repo on github and hitting
>> "download zip". I will check again
>>

Voltron

unread,
Mar 1, 2012, 4:54:20 PM3/1/12
to Humongolus
I am trying to render an empty test form:

class LoginHandler(BaseHandler):
''' '''
def get(self):
form = LoginForm()

context = {
'form' : form,
'page_content': '',
'page_title' : 'Login',
}

self.render("generic.html", **context)

def post(self):
print "arguments: ", self.request.arguments
form = LoginForm(data=self.request.arguments)

self.set_header("Content-Type", "application/json")

self.write(json.dumps(self.request.arguments))


The print in the POST handler prints

arguments:  {'_xsrf': ['536a0ec21b30487286284ab39fd61dcb'], > >
'password': ['None'], 'email': ['None']}

Another quick test


class PersonForm(widget.Form):
_action = '/save_person'
_fields = ["human", "name", "email"]
_id = "css_id"
_class= "css_class"
human = widget.Input(label="ID")
name = widget.Input(label="Name")
email = widget.Input(label="email")

form = PersonForm()

for f in form:
print
print f.render()


This prints:
<input name='human' value='None' id='id_human' type='text' />
<input name='name' value='None' id='id_name' type='text' />
<input name='email' value='None' id='id_email' type='text' />

What I mean to say, is, in a template or on the commandline, empty
forms are still being prefilled with value="none"

Christopher S Coté

unread,
Mar 1, 2012, 7:01:49 PM3/1/12
to humon...@googlegroups.com
I'm working up a little test app right now, seeing some issues as well.

I'll update tomorrow and hopefully have it all worked out.

Christopher Coté

unread,
Mar 2, 2012, 1:08:45 PM3/2/12
to humon...@googlegroups.com
Ok, I made another commit. Fixed a few bugs and also added an example app.

It requires Tornado, just run app.py from inside the example directory, it will run on port 8888.
Reply all
Reply to author
Forward
0 new messages