Not sure if this is a web2py or ckeditor problem or just some
misunderstanding on my part. Here's what's happening:
If I create a CKEditor instance in a SQLFORM, things work as expected until
I try to insert an image. Clicking the Ok button in ckeditor's image dialog
appears to be causing an immediate and unwanted form submission with a
formkey that doesn't match the real formkey. This doesn't raise a form
error. Instead it triggers the final else branch of the form.accepts logic
(see below) and the image along with any other text that was entered is
lost.
I recently ran into this in a larger app, but am able to reproduce it in the
following minimal model and controller. Has anyone else run into this and is
there a workaround other than switching the CKEditor to Source mode and
manually entering the <img> tag? I'm using web2py1.79.2 and CKEditor 3.3.1
(revision 5586) but have also seen the problem in CKEditor 3.2.
MODEL
db.define_table('page',
Field('body', 'text'),
)
def advanced_editor(field, value):
eid = str(field).replace('.','_')
return TEXTAREA(_id = eid, _name=field.name,
_class='text ckeditor', value=value,
_cols=80, _rows=10)
db.page.body.widget = advanced_editor
VIEW (default.py/index.html)
{{extend 'layout.html'}}
<script type="text/javascript"
src="{{=URL(request.application,'static','js/ckeditor/ckeditor.js')}}"></script>
{{=BEAUTIFY(response._vars)}}
CONTROLLER
def index():
form = SQLFORM(db.page, showid=False)
if form.accepts(request.vars,session):
response.flash = "Form accepted"
redirect(URL(r=request,f="show"))
elif form.errors:
response.flash = "Uh-oh!"
else:
## Trying to insert an image lands here.
response.flash = "Fill out the form."
return dict(form=form)
def show():
shown = dict()
for row in db(db.page.id>0).select():
shown[row.id] = row.body
return dict(shown=shown)
Thanks,
Mike