Models having selects with optgroups per Ticket #4412 no longer validate reliably
|Reported by:||thiggins||Owned by:||nobody|
|Severity:||Keywords:||model-validation, choices, optgroups|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Since Ticket #4412, nested choice structures have been permitted. This results in optgroups. The example that was given is reproduced here with one additional line:
choices = ( ('outer1', 'Outer 1'), ('Group 1', ( ('inner1', 'Inner 1'), ('inner2', 'Inner 2'), ('outer1', 'Outer 1'), ) ) )
In the development version, currently (version 1.2 alpha 1 SVN-12314), nested choice structures such as this still generate valid HTML, but associated models fail to validate unless the selection is from the 'outer' category, or happens to have the same value as a selection from the outer category (such as the line I added). Otherwise a default validation error message, such as 'Value u'inner1' is not a valid choice' is generated.
Let me point out that, in order to generate the HTML shown in #4412, eliminating a blank choice, one must follow the usage given 11/07/07 by semenov in Ticket #4653
using a combination of an explicit blank=False and a declared default value.