opal icon indicating copy to clipboard operation
opal copied to clipboard

Form templatetags: raise exceptions when unable to infer an enum

Open davidmiller opened this issue 6 years ago • 3 comments

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

davidmiller avatar Jun 14 '18 12:06 davidmiller

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).

rossjones avatar Jun 18 '18 13:06 rossjones

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.

fredkingham avatar Jun 18 '18 14:06 fredkingham

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.

fredkingham avatar Oct 30 '18 17:10 fredkingham