in last 10 minutes
Basic Steps for Creating a Custom Form Field
- Create a new Class
FormField::code_listingas 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).
- 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.