Was recently informed of a problem with plugin_ckeditor that I have been
trying to solve for a while now, but I think it may actually be a web2py
bug. First of all, here is the widget:
def widget(self, field, value, **attributes):
"""
To be used with db.table.field.widget to set CKEditor as the
desired widget for the field.
Simply set db.table.field.widget = ckeditor.widget to use the
CKEditor widget.
"""
default = dict(
value = value,
_cols = 80,
_rows = 10
)
attributes = FormWidget._attributes(field, default, **attributes)
attributes['_class'] = 'text plugin_ckeditor'
textarea = TEXTAREA(**attributes)
javascript = XML('some javascript code here')
result = [textarea, javascript]
return result
And here is a test controller:
def test():
form = SQLFORM.factory(
Field('requiredfield', required=True, notnull=True),
Field('textfield', 'text', widget=ckeditor.widget)
)
if form.accepts(request.vars, session, keepvalues=True):
response.flash = 'Accepted'
elif form.errors:
response.flash = 'There are some errors'
return dict(form=form)
This works great until there is a validation problem while submitting the
form. Once that happens, instead of getting CKEditor in the form for the
'textfield' field, I get "[<gluon.html.TEXTAREA object at 0x10961b3d0>,
<gluon.html.XML object at 0x10961b410>]".
I have tried wrapping both TEXTAREA and XML(javascript) into a single XML()
object, but when this happens, FORM will not pick up the value for the
field, even though it's in request.vars.
Thanks for your help.