problem with BooleanField form

46 views
Skip to first unread message

ed

unread,
Jul 20, 2011, 6:05:07 PM7/20/11
to Django users
I'm learning Django by following the turorials in Django 1.0 Website
Development by Ayman Hourieh. I've been banging my head for a while on
this and I know it's probably something really simple that I'm
missing.

I'm using the following form:

class BookmarkSaveForm(forms.Form):

share = forms.BooleanField(
label=u'Share on the main page',
required=False
)


So when the form displays fine, but when I check the checkbox and
submit the form I get the following for form.cleaned_data:

{'share': False}

Shouldn't I be seeing "'share': True", not "'share': False"? Or am I
understanding this incorrectly?

SmileyChris

unread,
Jul 20, 2011, 7:12:29 PM7/20/11
to django...@googlegroups.com
It should definitely be {'share': True} if you've checked the box and submitted the form.

Have you ensured your checkbox inside the form tag you're submitting in HTML?

ed

unread,
Jul 20, 2011, 11:00:55 PM7/20/11
to Django users
I'm using the following javascript, so I can't check the HTML, can I?
How would I go about debugging this?

function bookmark_save() {
var item = $(this).parent();
var data = {
url: item.find("#id_url").val(),
title: item.find("#id_title").val(),
tags: item.find("#id_tags").val()
};
$.post("/save/?ajax", data, function (result) {
if (result != "failure") {
item.before($("li", result).get(0));
item.remove();
$("ul.bookmarks .edit").click(bookmark_edit);
}
else {
alert("Failed to validate bookmark before saving.");
}
});
return false;
}

function bookmark_edit() {
var item = $(this).parent();
var url = item.find(".title").attr("href");
item.load(
"/save/?ajax&url=" + encodeURIComponent(url),
null,
function () {
$("#save-form").submit(bookmark_save);
}
);
return false;
}

$(document).ready(function () {
$("ul.bookmarks .edit").click(bookmark_edit);
});

Daniel Roseman

unread,
Jul 21, 2011, 4:29:17 AM7/21/11
to django...@googlegroups.com
But surely the problem is that you haven't supplied a value for  `share` in your Ajax data.
--
DR.

ed

unread,
Jul 21, 2011, 1:49:40 PM7/21/11
to Django users
You mean like this:

var data = {
url: item.find("#id_url").val(),
title: item.find("#id_title").val(),
tags: item.find("#id_tags").val(),
share: item.find("#id_share").val()
};

Tried it. 'share' is still showing up false...

ed

unread,
Jul 22, 2011, 11:42:49 AM7/22/11
to Django users
Ok. That last one actually worked. Just needed to a browser refresh to
re-load the script.

That's a total noob mistake. My bad. Thanks all :)
Reply all
Reply to author
Forward
0 new messages