I have a form that has disabled select box. I have this function in UpdateForm():
def clean_job(self):
f = self.fields['job'].widget.attrs
if f.has_key('disabled') and f['disabled'] == 'disabled' :
return self.instance.job
else:
return self.cleaned_data['job']
But when submitting the form I have this error : Key 'job' not found in <QueryDict:
How can I assign a key for a disabled selectbox?
Thanks in advance
You don’t have to send send something for
jobto the server. What you have to do is properly handle exceptions in your code. Accessing a key directly in a dictionary will result in an error if that key doesn’t exist, so you simply don’t do that. Instead, use thegetmethod on the dict, orQueryDictin this case.Or you can provide a default value: