opal icon indicating copy to clipboard operation
opal copied to clipboard

if an input has choices, have a radio field by default

Open fredkingham opened this issue 7 years ago • 3 comments

at the moment if we scaffold an app with a charfield with choices field it will put in an input field, lets use a radio field

fredkingham avatar Mar 09 '17 17:03 fredkingham

Hi, I wanted to contribute. Is this still an issue.

C09 avatar Jun 15 '20 05:06 C09

Hi Chandni

It hasn't and a contribution would be great.

Some background that may help... (this may be obvious, if so sorry!)

In terms of fields with options 4 template tags exist input, select, radio and radio_vertical .

Input renders an input field that is free text but with autocomplete options, select is an html select tag and radio/radio_vertical are radio button fields.

When you run python manage.py scaffold. opal.core.scaffold renders opal/core/scaffolding/record_templates/record_form.jinja2

This looks at the schema for the field (the schema is a serialized version of the model structure) and if its a charfield (ie type string in the schema) it renders an input template tag, with the autocomplete options.

However the most common case we have found that is if you are rendering a charfield with choices is that you want a radio field.

In the schema the choices are serialized in the enum field of the schema.

The solution is that in the record_form.jinja2 check that a field is a string field and check to see if the enum field is populated and if so to use a radio field.

fredkingham avatar Jun 15 '20 12:06 fredkingham

also https://github.com/openhealthcare/opal/blob/v0.18.4/CONTRIBUTING.md if you haven't seen it

fredkingham avatar Jun 15 '20 12:06 fredkingham