Python pyramid - How to use checkboxes and radio buttons

北慕城南 提交于 2019-12-04 18:36:51

Have you tried put

defaults={"groups" : True}

in Form ctor, for example (in pyramid_simpleform doc):

form = Form(request, MySchema, defaults={"name" : "foo"})

I use FormRenderers to output forms and also had problems using Checkboxes. So I wrote the following class that replaces the FormRenderer from simple_form in all my views:

# -*- coding: utf-8 -*-
from pyramid_simpleform.renderers import FormRenderer as OldFormRenderer
from webhelpers.html import tags

class FormRenderer(OldFormRenderer):
    def checkbox(self, name, value="1", checked=False, label=None, id=None, 
             **attrs):
        """
        Outputs checkbox input.
        """
        id = id or name
        return tags.checkbox(name, value, checked, label, id, **attrs)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!