I think you want this:
class CustomWIdget():
def __init__(self, parameters=None):
pass
def html(self):
return DIV(self.field.name)
def __call__(self, field, value):
self.field = field
self.value = value
return self.html() #this doesnt return html markup, escaped text
instead
db.define_table("table1",
Field("myField", "string", widget=CustomWidget() )
)
On Friday, 25 April 2014 22:40:57 UTC-5, [email protected] wrote:
>
>
> Hi, Im having troubles defining widgets as classes. When widgets are
> defined as functions it all works well, the function returns a html
> object(DIV, UL, ...) and the view renders the markup correctly, but im
> trying to define the widget as a class to handle static files requirements
> for that widget.
>
> I have tried the __str__ method to render the widget but the view(or
> SQLFORM) renders as text, not html markup.
>
> Here is some example code:
>
> #Widget as a function
> def CustomWidget(field, value):
> return DIV(field.name, _class="myClass")
>
> #Widget as a class
> class CustomWIdget():
>
> def __init__(self, field, value):
> self.field = field
> self.value = value
>
> def html(self):
> return DIV(self.field.name)
>
> def __str__(self):
> return str(self.html()) #this doesnt return html markup, escaped
> text instead
>
> db.define_table("table1",
> Field("myField", "string", widget=CustomWidget)
> )
>
> Thanks in advance.
>
>
--
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.