0

我正在为 web2py 使用 CKEditor 插件。我遇到的问题是,在表单上,​​当有人单击下拉值时,使用 javascript 提交表单,request.vars 中的 id 用于生成新的表单值(form.vars.body),直到代码到达 form.accepts(req..., sess..)。由于某种原因,小部件值(form.vars.body)在提交之前更改为原始值(其他 form.vars 字段更改并正常工作)。我的问题是 form.accepts(req.., ses..) 是否再次更改或调用小部件代码中的任何内容以将该特定字段恢复为其原始值。

query1 = db.contents.event_instance_id==event_instance_id
query2 = db.contents.section==section_id

contents = db(query1 & query2).select(db.contents.id, db.contents.title,db.contents.body).first()

record=contents.id
fields = ['id','section', 'title', 'body']

# get form
# this returns the correct form.xml with the right content for db.contents.body
form = SQLFORM(db.contents, record, fields=fields, submit_button=T('Save Content'))

if form.accepts(request.vars, session):
    response.flash = T("Contents saved")
elif form.errors:
    response.flash = T("Error saving content")

# but after form.accepts the form.xml is different, form.vars.body is different, 
# which is then passed to the view with the wrong content for the field with widget
return dict(form=form, title=title, event_instance_id=event_instance_id)

in the model

db.define_table('contents', Field('event_instance_id', 'reference event_instance', label='Event Instance'), Field('section', 'reference sections'), Field('title', length=255, requires=IS_NOT_EMPTY()), Field('body', 'text', requires=IS_NOT_EMPTY(), widget=ckeditor.widget) )

在视图中它只是{{=form}}

4

0 回答 0