View · Index

Basic Steps for Creating a Custom Form Field

  1. Create a new Class 
    FormField::code_listing
    as subclass of ::xowiki::FormField::textarea. One can write the new class definition in an own package (see next section, subclassing xowiki), or by adding an additional file to xowiki/tcl/, but make sure this file is loaded after xowiki's form-field procs.

    By defining our new class as a subclass of ::xowiki::FormField::textarea we inherit the input semantics (when someone enters code example into a form page via editing the form page).

    In our new class, we define, the how pretty-printing of the code should be performed. For this purpose, we define a method pretty_value to compute the rendering, when a field of this type is viewed (see sample code on next page).

  2. Create a new xowiki::Form instance from the user interface,

    • define a form-field named e.g. "listing" "Form" or "Template" sections of the form, and

    • specify that "listing" is of type "code_listing" (our newly defined class) in the form constraints with a form constraint like e.g. listing:code_listing.

  3. The next page shows a form page with the new form field type in action.