opal
opal copied to clipboard
Form templatetags: raise exceptions when unable to infer an enum
Opal form templatetags attempt to infer enums. They look at Django Choices, Opal Lookuplists or arbitrary JSON passed in the template.
Two enhancements would improve this functionality:
- When passed a Boolean/NullBoolean field, know that the options are e.g. Yes/No/Unknown
- When a widget that requires an enum (Select, Radio) can't find one, raise an exception rather than rendering an empty widget
Presumably, Unknown is only an option for NullBoolean fields?
For choice fields, it appears that return [i[1] for i in choices]
returns only the display string part of the tuple, how does it find the values it can use (for the bool it should probably be True, False, None).
At the moment we just save the display part of the string because tbh that's just the only usecase we could conceive of wanting.
So this will require some value
work on the radio buttons https://docs.angularjs.org/api/ng/input/input%5Bradio%5D
yes please for the None/Unknown plan.
I think we need to rethink this. There are 2 options.
Move logic into the field translator and do a hard coded if field type == Boolean or NullBoolean then translate yes, no, unknown accordingly.
Use logic similar to what is included here but change it so that we use a dictionary which populates value. I'm pro the latter as it doesn't require angular. The problem is any instances where we have hardcoded lookup list properties that currently takes a string that we include as javascript in the template.
Its an interesting one, but lets hold off for the time being.