Forum OpenACS Q&A: setting the richtext format in ad_form

Hi, I can't quite figure out how to do this. I would like to set the "format" value for a richtext widget while using ad_form. Here's my code:

ad_form -name department_form -action department-ae -form {
    {department_id:key}
    {abbrev:text {label "Abbreviated Code"} {html {size 4 maxlength 20}}}
    {label:text {label "Label"} {html {size 40 maxlength 255}}}
    {description:richtext(richtext) {label "Description"} {html {rows 10 cols 40}}}
} -new_request {
} -edit_request {
    db_1row get_instructor_info { select abbrev, label, description, description_format from course_departments where department_id = :department_id }
    template::util::richtext::set_property contents description $description
    template::util::richtext::set_property format description $description_format
} -validate {
} -on_submit {
    set description_format [template::util::richtext::get_property format $description]
    set description [template::util::richtext::get_property contents $description]
} -new_data {
    set department_id [department::create -department_id $department_id -abbrev $abbrev -label $label -description $description -description_format $description_format]
} -edit_data {
    department::edit -department_id $department_id -abbrev $abbrev -label $label -description $description -description_format $description_format
} -after_submit {
    ad_returnredirect "departments"
    ad_script_abort
}

It extracts the format when it is submitted and stuffs that value into the database, but when i return to this page to edit the content it reverts back to "enhanded text".

The line template::util::richtext::set_property contents description $description doesn't actually do anything, but form api-doc it seemed like this was needed. i think the pull from the database with a field named "description" is what sets that value. Thanks for the help!

Collapse
Posted by Ola Hansson on
Matthew,

In the edit_request the data should be encode into a list consisting of the contents and the format, like this (there might be a special proc call for this, I'm not sure):

set description [list $description $description_format]

Whenever the form has been submitted (from the initial state or from the edit_request state), the "executing" block such as new_data and edit_data in this case expects $description in the encoded list form. So you should probably decode the list like you've done in the on_submit block in each of those blocks instead and get rid of the on_submit block (or at least what is performed inside of it).

For an example that works, see: http://cvs.openacs.org/cvs/openacs-4/packages/curriculum/lib/element-ave.tcl?view=auto&rev=1.9

HTH

/Ola

Collapse
Posted by Matthew Geddert on
Thanks, that did it!