I don’t understand what’s happening, I have in my form
mylist = forms.MultipleChoiceField(required=False, widget=forms.SelectMultiple, label='MyList',help_text = "help")
I then have some jquery on the page that adds dynamic values to this, but when I submit the form I get form.is_valid to false “object has no attribute ‘cleaned_data'”
This seems to only happens when after i dynamically add values to the select box if I select some before submitting. If I don’t select values the cleaned_data[“mylist”] is empty array.
How do I fix this? Basically I want to access my dynamically added list of values from django form after submission.
edit
-----
if request.method == 'POST':
form = MyForm(request.POST)
action = request.POST['submit']
if action == 'Update':
mylist = form.cleaned_data['mylist']
else:
form = MyForm()
edit
def clean_mylist(self):
data = self.cleaned_data('mylist')
return data
def clean(self):
cleaned_data = self.cleaned_data
return cleaned_data
When you submit the form
MultipleChoiseFieldvalidates that all selected items belong to choises parameter of theMultipleChoiseField. If you dynamically later add fields they are naturally not in the choises set. Read more here.As solution you could think of using
CharFieldwithSelectMultiplewidget and override the clean-method.