Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fredkingham opened this issue Mar 9, 2017 · 3 comments
Open

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

fredkingham opened this issue Mar 9, 2017 · 3 comments

Comments

@fredkingham
Copy link
Contributor

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

@C09
Copy link

C09 commented Jun 15, 2020

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

@fredkingham
Copy link
Contributor Author

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
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants