[<< wikibooks] XForms/A Trigger for Inserting BBcode into a Textarea box
== Using Trigger to Add BBcode or Other Text to Input or Textarea Controls ==
Here is a simple way to use a button (trigger) to add commonly used text to your xforms-input or xforms-textarea controls. This could be many things such as BBcode (bold/unbold codes), date-time stamps, frequently used formatted text such as a letterhead, signature blocks, special codes that aren't easy to remember-- all depending on the purpose of your form and your specific needs.

== Link to working XForms Application ==
Load Example XForms Application

A more advanced example for inserting at the beginning or end of text (with some additional code inserts such as links and images)
Load Example XForms Application

== Program Structure ==
For simplification, we are using a single  element in our model/instance to hold our example input. The style is not really necessary other than to give one a larger text area to test with.
The real power, and simplicity, of the form is in the value attribute of the xforms-setvalue element which itself is placed inside an xforms-trigger:

  value="concat(//text,'whatever you desire goes here')"

== Sample Program ==

== Discussion ==
This solution will only append the inserted code/text to the end of the current text in the text box. To have it always at the beginning, simply change the order of the arguments in your concat function (see the second example link above).
Limitation: This solution cannot insert code/text into the middle of the current text in the text box.
You can use html entities to do complex formats like a letterhead (if you need to preserve space or bold etc..)
(!!note: the ampersand-& is replaced by the percent-% as I couldn't figure out how to escape html   entities in this wikibook)

In such a case, make sure your xforms-output has a mediatype attribute like so:

== Discussion ==