I can't get a form to validate and for the life of me, can't figure
out why.
I keep getting an error on the topics. Regardless of how many I
choose, it returns an "Enter a list of values." error. It looks like
even though the form returns a list of topics, it doesn't send the
list to the validator, just a single value.
I've also tried converting the topics bit to a MutlipleChoiceField,
but didnt' have any mroe luck with it.
Any suggestions of where to look are much appreciated. Thanks,
dan
class AddBlogForm(forms.Form):
def __init__( self, *args, **kwargs ):
super( AddBlogForm, self ).__init__( *args, **kwargs )
self.fields['location'] =
GroupedChoiceField(choices=location_drop_tags())
self.fields['topics'] = forms.ModelMultipleChoiceField(
queryset=Tags.objects.exclude(location__exact=True).order_by('-
parent_tag', 'tag'), widget=SortedCheckBox)
owner = forms.CharField()
password = forms.CharField(widget=forms.PasswordInput)
url = forms.URLField(initial='http://', verify_exists=True)
title = forms.CharField(max_length=100)
description = forms.CharField(max_length=500, required=False,
widget=forms.Textarea(attrs={'rows': '3'}))
(this is the widget used for the topic)
class SortedCheckBox(forms.Select):
def render(self, name, value, attrs=None, choices=()):
from django.utils.html import escape
from django.newforms.util import flatatt, smart_unicode
final_attrs = self.build_attrs(attrs, name=name)
output = []
if value is None:
value = ''
str_value = tuple([smart_unicode(v) for v in value])
for t in
self.choices.queryset.filter(parent_tag__isnull=True):
output.append(u'<div style="width:100px; float:left;">')
option_value = smart_unicode(t.id)
option_label = smart_unicode(t.tag)
selected_html = (option_value in str_value) and u'checked
' or ''
output.append(u'<input type="checkbox" name="topics"
value="%s" %s/><b>%s</b><br />' % (option_value, selected_html,
option_label))
for t_child in
self.choices.queryset.filter(parent_tag__tag=t.tag):
option_value = smart_unicode(t_child.id)
option_label = smart_unicode(t_child.tag)
selected_html = (option_value in str_value) and
u'checked ' or ''
output.append(u'<input type="checkbox" name="topics"
value="%s" %s/>%s<br />' % (option_value, selected_html,
option_label))
output.append(u'</div>')
return u'\n'.join(output)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---