In Django, how do I check for a (plural) cholice field when a selection is added by Javascript?

I have ChoiceField

where the selection is not known during HTML rendering; they are dynamically defined by the user and added to the form via Javascript, but validation naturally fails as the selected option is not in the select attribute (which is just an empty list). I tried to set the field to CharField

, but then the validator just gets a string value that needs to be converted to a list before it can be used. Ah, and I would like to avoid subclassing the field class like this only once.

Hope this is clear. Any ideas?

+3


source to share


1 answer


Do not subclass the field class, but override the method clean_<yourfield>

in the class Form

. See the Docs here .



0


source







All Articles