Ok Fabiano, no issue with SQLFORM.widgets.checkboxes.widget...

I didn't know exactly how it works :)

In this thread look for Bruno's answers that how I figure out how to pass
the proper default to widget :
https://groups.google.com/forum/?fromgroups#!searchin/web2py/%5Bweb2py%5D$20requires$20and$20T()/web2py/f60S4rwwHnY/w8w4hPMYMigJ

Basically, since there is multiple checkboxes you need to define a
IS_IN_SET requires with your options set (your check boxes) and then you
can define a default by passing to default the label of what you use as
label for the differents checkboxe in your defined set.

Here a example :

    form = SQLFORM.factory(
        Field('test', type='boolean', requires=IS_IN_SET([1,2,3],
multiple=True), widget=SQLFORM.widgets.checkboxes.widget, default = 3),

I pass to default "3" since that the box that I want to be ckecked by
default.

In order to pass more then one choice you just pass a list to default like
this :

    form = SQLFORM.factory(
        Field('test', type='boolean', requires=IS_IN_SET([1,2,3],
multiple=True), widget=SQLFORM.widgets.checkboxes.widget, default = [2,3]),
        formstyle='divs'
        )

Hope it helps...

I appreciate answer your question since it helps me understand something I
will have to cover in the coming days for a particular form.

Ciao!

Richard

On Wed, Jul 11, 2012 at 3:52 PM, Richard Vézina <[email protected]
> wrote:

> Fabiano,
>
> I think there is an issue with widget=SQLFORM.widgets.checkboxes.widget do
> you use it?
>
> I try without widget=SQLFORM.widgets.checkboxes.widget and I can set
> default=True and I get a checked box, but if I use it the box doesn't get
> checked.
>
> If you don't need the fancy feature of widget (I think that it is mostly
> to have many checkboxes for the same field and specify labels for those
> multiple checkboxes) avoid using it could solve your issue.
>
> I will investigate further why and how SQLFORM.widgets.checkboxes.widget
> could be broken.
>
> Richard
>
>
> On Wed, Jul 11, 2012 at 1:50 PM, Fabiano Faver <[email protected]> wrote:
>
>> the field is shown if I dont declare the type, however the checks are not
>> checked with default=True, like I wrote
>>
>> Em quarta-feira, 11 de julho de 2012 07h35min46s UTC-3, villas escreveu:
>>
>>> Don't you need a list field type for 'usuarios'?
>>>
>>>
>>> On Tuesday, July 10, 2012 9:49:40 PM UTC+1, Fabiano Faver wrote:
>>>>
>>>> controller:
>>>>
>>>> def gerenciar_grupos():
>>>>
>>>> form_not_usu = SQLFORM.factory(
>>>> Field('usuarios', requires=IS_IN_DB(db, db.auth_user,'%(email)s',**
>>>> multiple=True),widget=SQLFORM.**widgets.checkboxes.widget,
>>>> default=True),
>>>>                                 )
>>>> return dict(  form_not_usu = form_not_usu)
>>>>
>>>>
>>>>
>>>> view:
>>>>
>>>> {{extend 'layout.html'}}
>>>> {{=form_not_usu.custom.begin}}
>>>>
>>>> <ul>
>>>> {{for x in form_not_usu.custom.widget.**usuarios:}}
>>>> {{=LI(x)}}
>>>>
>>>> {{pass}}
>>>> </ul>
>>>>
>>>> {{=form_not_usu.custom.submit}**}
>>>> {{=form_not_usu.custom.end}}
>>>>
>>>>
>>>>
>>>> Checkboxes are not checked when accessing the page.
>>>>
>>>> Em terça-feira, 10 de julho de 2012 16h46min48s UTC-3, Richard escreveu:
>>>>>
>>>>> in your model Field(..., default=True) or in the controller
>>>>> db.table.field.default=True
>>>>>
>>>>> You also need to use checkbox widget.
>>>>>
>>>>> Richard
>>>>>
>>>>> On Tue, Jul 10, 2012 at 2:39 PM, Fabiano Faver <[email protected]>wrote:
>>>>>
>>>>>> I want to creat something similar to SQLFORM(auth_membership) but I
>>>>>> want the user to choose a group and all users show up as checkboxes and
>>>>>> users who already belong to this group are checked as well.
>>>>>>
>>>>>> I`m downt know how to pre-select these auth_users.
>>>>>>
>>>>>> any tips?
>>>>>>
>>>>>
>>>>>
>

Reply via email to