﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
12363	Add add() method to ErrorDict class	miracle2k	nobody	"When doing form validation, in some cases you want to add an error message to a field other than the one you are currently validating, or add an error message to a field while inside the form's global clean() method. Usually this is because in order to validate a given field you need access to the data of another field that is not yet cleaned.

(For example, I have a form with two fields, ""page"" and ""url"", only one being required).

Currently, doing this requires accessing the form._errors dict and injecting the error message. This gets cumbersome when you want to ""do the right thing"" and not override existing error messages. I.e. you have to do something like:

{{{
if does_not_validate():
    self._errors.setdefault('the_field', ErrorList())
    self._errors['the_field'] += ['Fix this value']
}}}

I feel like it would be a nice addition of ErrorDict had something like add() or set() methods:

{{{
if does_not_validate():
    self.errors.add('the_field', 'Fix this value')
}}}

If you want to override all existing errors, you could do:

{{{
if does_not_validate():
    self.errors.set('the_field', 'Fix this value')
}}}

Possibly an alternative approach would be to allow raising a ValidationError with a dict:

{{{
if does_not_validate:
    raise ValidationError({'the_field': 'Fix this value'})
}}}"		closed	Forms			duplicate			Accepted	0	0	0	0	0	0
