Would you I make a patch on Github?

Richard


On Tue, Dec 3, 2013 at 12:58 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> I opened a ticket and will process asap.
>
>
> On Monday, 2 December 2013 14:46:41 UTC-6, Richard wrote:
>>
>> Hello,
>>
>> I set a label True/False flag for checkbox widget like so :
>>
>> class CheckboxesWidget(OptionsWidget):
>>
>>     @classmethod
>>     def widget(cls, field, value, **attributes):
>>         """
>>         generates a TABLE tag, including INPUT checkboxes (multiple
>> allowed)
>>
>>         see also: :meth:`FormWidget.widget`
>>         """
>>         # was values = re.compile('[\w\-:]+').findall(str(value))
>>         if isinstance(value, (list, tuple)):
>>             values = [str(v) for v in value]
>>         else:
>>             values = [str(value)]
>>
>>         attr = cls._attributes(field, {}, **attributes)
>>         attr['_class'] = attr.get('_class', 'web2py_checkboxeswidget')
>>
>>         label = attr.get('label')
>>         if not isinstance(label, bool):
>>             label = True
>>         elif label is True:
>>             label = True
>>         elif label is False:
>>             label = False
>>
>>         requires = field.requires
>>         if not isinstance(requires, (list, tuple)):
>>             requires = [requires]
>>         if requires and hasattr(requires[0], 'options'):
>>             options = requires[0].options()
>>         else:
>>             raise SyntaxError('widget cannot determine options of %s'
>>                               % field)
>>
>>         options = [(k, v) for k, v in options if k != '']
>>         opts = []
>>         cols = attributes.get('cols', 1)
>>         totals = len(options)
>>         mods = totals % cols
>>         rows = totals / cols
>>         if mods:
>>             rows += 1
>>
>>         #widget style
>>         wrappers = dict(
>>             table=(TABLE, TR, TD),
>>             ul=(DIV, UL, LI),
>>             divs=(CAT, DIV, DIV)
>>         )
>>         parent, child, inner = wrappers[attributes.get('style', 'table')]
>>
>>         for r_index in range(rows):
>>             tds = []
>>             for k, v in options[r_index * cols:(r_index + 1) * cols]:
>>                 if k in values:
>>                     r_value = k
>>                 else:
>>                     r_value = []
>>                 tds.append(inner(INPUT(_type='checkbox',
>>                                        _id='%s%s' % (field.name, k),
>>                                        _name=field.name,
>>                                        requires=attr.get('requires',
>> None),
>>                                        hideerror=True, _value=k,
>>                                        value=r_value),
>>                                  LABEL(v, _for='%s%s' % (field.name, k))
>> if label is True else ''))
>>             opts.append(child(tds))
>>
>>         if opts:
>>             opts.append(
>>                 INPUT(requires=attr.get('requires', None),
>>                       _style="display:none;",
>>                       _disabled="disabled",
>>                       _name=field.name,
>>                       hideerror=False))
>>         return parent(*opts, **attr)
>>
>> The purpose of this change is in context where a user need single
>> checkbox for each row of a grid where he don't need to display a label
>> beside the checkbox, since he only want to know which record is checked and
>> need to be updated...
>>
>> I need that in order to create a special form that allow bunch/batch
>> records update, see attach image (sorry I had to hide data of some
>> columns)... You can see, that each row has a checkbox that is generated
>> like this :
>>
>> form_fields = [Field('checkbox_%s' % r['table'].id, 'integer',
>>                          requires=IS_EMPTY_OR(IS_IN_
>> SET([r['table'].id])),
>>                          widget=lambda field, value:
>> SQLFORM.widgets.checkboxes.widget(field, value, style='divs',
>> label=False)) for r in rows]
>>
>> The form is then create with .factory() after adding the last fields of
>> the models that appears in the last line of the html table on the attach
>> image...
>>
>> I can, make the change on Git and send a PR, if this change is kind of
>> approved!!
>>
>> Thanks
>>
>> Richard
>>
>>  --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to