Radiobox instead of default widget for field of type List

Where and what should be the changes made to replace the default widget(in and out select widget) for List type with RadioFieldWidget? I am building an addon for plone5 and using autoform 1.7.

In the file that contains the following class:

class FilterForm(form.SchemaForm):

schema = IFilterForm
ignoreContext = True
label = u"Filter"
description = u"Filter after certain criteria."

I imported

from import RadioFieldWidget

and the schema is defined in an xml file with fields like:

  <field name="supported_python_versions"
         type="zope.schema.List" >
    <title i18n:translate="">Supported Python Versions</title>
    <description i18n:translate="">Choose the list of supported Python versions</description>
    <value_type type="zope.schema.Choice">

Is there a way to change the widget to radioField and pass the vocabulary to it?

even as you can use a radio button as the widget to select multiple options on a list, I think it's not a good idea from the UI point of view and seems not to be supported in the current implementation neither, as the name attribute of all the input tags has to have the same value.

I would suggest you to use a checkbox widget instead:

from z3c.form.browser.checkbox import CheckBoxWidget

I actually want to enable only one option being selected from list. So I thought of using radio button. My doubt is what should be the changes made after importing the respective Widgets?

then you have to use a Choice field instead of a List one.

1 Like