complex form with jquery filling fields

8 views
Skip to first unread message

Grigory Fateyev

unread,
Nov 6, 2009, 4:37:06 AM11/6/09
to django...@googlegroups.com
Hello!

I need to write complex form, in that form users can select some params
(popup select fields) than fill other fields via ajax query. JS was
successfull written and fields are filling well, but when I submit
form, validation said something like that: "It's not correct value for
this field." Now I try in form init to query list for choices
and $('... option').remove(); in JS code, but it's wrong way, because I
have to load hole list. How django users solve this problem?

Code example:
class TestForm(forms.ModelForm):
board = forms.MultipleChoiceField()
...
class Meta:
...
fields = ('board',)

def __init__(self, *args, **kwargs):
super(SellUnitForm, self).__init__(*args, **kwargs)
self.fields['board'].choices =
TypeOfBoard.objects.all().values_list('id', 'name')

def save(self, commit=True):
# Here is custom save.
return super(TestForm, self).save(commit)

--
Всего наилучшего! Григорий
greg [at] anastasia [dot] ru
Письмо отправлено: 2009/11/06 12:20

Reply all
Reply to author
Forward
0 new messages