I have got something like this working - basically based on the hradio
widget which was developed by s-cubism
so I define a widget in a module along the following lines:
def hcheckbutton_widget(field, value, **attributes):
rows = SQLFORM.widgets.checkboxes.widget(field, value).elements('tr')
inner = []
for row in rows[:-1]:
button, label = row.elements('td')[0]
label.attributes.update(_for=button.attributes['_id'],
_class='btn btn-xs', _autocomplete="off")
inner.append(SPAN(button, ' ', label, _style='padding-right:10px;'))
return DIV(_class='btn_group', *inner, **attributes)
You would then attach the widget to a field in your model or controller eg:
db.viewscope.filters.requires = IS_IN_SET(['Scope', 'Category',
'AnswerGroup', 'Date', 'Event'], multiple=True)
db.viewscope.filters.widget = hcheckbutton_widget
So this gives you horizontal buttons with a checkbox next to them - which I
think is OK as makes display clearer as to what is selected. Final step
for me was some javascript on the form to add another class for checked
buttons and user selection. The following stuff works if you are happy to
apply to all checkboxes on the form. Some scenarios might allow at least
initial classes to be set when the widget runs - however I change my
selections after the form is created so it didn't work for me.
So I have the following javascript included in the view and within a
document ready function:
$('input[type=checkbox]').each(function() {
if ($(this).prop('checked')) {
$(this).next().addClass('btn-success');
}
});
$('input[type=checkbox]').click(function () {
$(this).next().toggleClass("btn-success")
});
This just uses bootstrap 3 btn-success class to get green buttons for the
selected ones but it doesn't use the javascript function you suggested.
However hopefully gives you a suggestion of one way to get working.
Regards
Donald
On Saturday, August 13, 2016 at 4:14:55 PM UTC+1, clara wrote:
>
> Hello,
>
> I would like to use this tabselect (tabselect widget
> <http://fredibach.ch/jquery-plugins/tabselect.php>) widget instead of the
> web2py's default multiselect widget.
>
>
> <https://lh3.googleusercontent.com/-mAmSBvuEAjE/V681EsU0p_I/AAAAAAAAU1E/O4y0Es-8d4w26CVOI4Z3dmOOGUgCTUHUACLcB/s1600/tabselect.PNG>
>
> I have now a simple:
> form = SQLFORM(db.mytable)
>
> to get the form in place and I just want to use this widget for one of the
> fields.
>
> I did some testing with the widget and I know how to initialize it or to
> retrieve the selected values to update the record. But I am not so sure
> about how to integrate this in a form.
>
> I understand that there are two approaches to get this done but I am
> really in doubt about which path to follow.
> - Define a custom widget (seems obscure to me); or
> - "Build" the form field by field to get my widget in the form. However, I
> would also need to "append" the widget information to the submit data.
>
> I will appreciate any hints or suggestions on this. Best regards,
>
> Clara
>
>
>
>
>
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.