Django validates form data in this order when calling is_valid or
full_clean:

1. run the clean method of the form field itself. Here:
DateTimeField.clean()
2. then run the clean_<fieldname>() method of the form if available
3. once those two methods are run for every field, run the clean()
method of the form

Source: 
http://docs.djangoproject.com/en/1.1/ref/forms/validation/#form-and-field-validation

So I guess the cleaned_data dict has no 'some_hidden_field' key.
DateTimeField.clean() probably raised a Validation Error and did not
populate the cleaned_data dictionary.

Try the following:

def clean(self):
        cleaned_data = self.cleaned_data
        #cleaned_data.get(key) returns None if key does not exist
        some_hidden_field = cleaned_data.get("some_hidden_field")

        if some_hidden_field:
            #do your custom validation here and raise ValidationError
if necessary
        # Always return the full collection of cleaned data.
        return cleaned_data

On Mar 22, 3:31 pm, gentlestone <tibor.b...@hotmail.com> wrote:
> this piece of code leads to Key error 'some_hidden_field'
>
> class XyForm(Form):
>
>     some_hidden_field =
> forms.DateTimeField(widget=forms.HiddenInput())
>
>     def clean(self):
>         some_hidden_field = self.cleaned_data['some_hidden_field']
>
> Why are hidden fields not cleaned?
> I need to validate the hidden value and raise VadiationError if the
> value is not ok.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to