In current time i rewrote mede a simple widget
but this widget work only for firefox
class MyOptionsWidget(FormWidget):
@staticmethod
def has_options(field):
"""
checks if the field has selectable options
:param field: the field needing checking
:returns: True if the field has options
"""
return hasattr(field.requires, 'options')
@classmethod
def widget(cls, field, value, **attributes):
"""
generates a SELECT tag, including OPTIONs (only 1 option allowed)
see also: :meth:`FormWidget.widget`
"""
default = dict(value=value)
attr = cls._attributes(field, default,
**attributes)
options = db().select(db.provider.ALL)
opts = []
for option in options:
opts.append(OPTION(option.name, _value=option.id,
_style='background-image:url("%s"); '
'background-repeat : no-repeat;
padding-left: 20px;' %
URL('download', args=option.image)))
return SELECT(*opts, **attr)
вторник, 29 апреля 2014 г., 2:32:42 UTC+5 пользователь Massimo Di Pierro
написал:
>
> The best way is just to give it a class
>
> SQLFORM
> <http://127.0.0.1:8000/examples/global/vars/SQLFORM>.widgets.options.widget(field,
> value, _class="myclass" % field.image)
>
> and then use JS (something like this):
>
> jQuery(function(){
> jQuery('.myclass option').each(function() {
> var image=jQuery(this).html()+'.png'
> jQuery(this).css('background-image','url('+image+')');
> });
> });
>
>
> On Monday, 28 April 2014 14:02:55 UTC-5, [email protected] wrote:
>>
>> I have a tables
>>
>> db.define_table('provider',
>> Field
>> <http://127.0.0.1:8000/examples/global/vars/Field>('name'),
>> Field
>> <http://127.0.0.1:8000/examples/global/vars/Field>('image', type='upload'),
>> format='%(name)s',)
>>
>>
>> db.define_table('payment',
>> Field
>> <http://127.0.0.1:8000/examples/global/vars/Field>('provider', 'reference
>> provider'),
>>
>> ...
>>
>>
>> how i can use "SQLFORM<http://127.0.0.1:8000/examples/global/vars/SQLFORM>
>> .widgets.options.widget"
>>
>> def index():
>> db.payment.provider.widget = lambda field, value: \
>> SQLFORM
>> <http://127.0.0.1:8000/examples/global/vars/SQLFORM>.widgets.options.widget(field,
>> value, _style='background-image:url(%s);' % field.image)
>>
>>
>> to get something like this
>>
>> <select>
>> <option style="background-image:url(provider1.png);">Provider1</option>
>> <option style="background-image:url(provider2.png);">Provider2</option>
>> <option style="background-image:url(provider3.png);">Provider3</option>
>> </select>
>>
>> Thanks.
>>
>
--
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.