Controller file location
Web Form controllers are always called controller.js and sit along side a companion XFORM Definition inside a web form folder within the repository. A web form folder can be any arbitrary depth below the following path /company_home/ecr/config/forms
company_home
|
+--ecr
|
+--conifg
|
+--forms
|
+--myFormCategory
|
+--myForm
|
+--controller.js
|
+--xform.xml
Required Controller Content
You must declare a controller config and populate the variable controller via the controller factory.
Two types of controllers are currently supported:
- WcmController
- DmController
var config = { contentType: "/mySite-com/page/news/item", instanceName: "instance", enableDeployToTestServer: "true" }; controller = CitrixFormsEngine.ControllerFactory.newWcmController(config);
Web Form Controller Methods
onLoad
This method is called when the form is being loaded. It is ideal for loading and transforming data in the various models sent in to the main form controller.
OnBeforeSave
This method is called after validation and before save and can be used to populate fields in the XML with values from the form
OnSave
On is call right before the content is persisted
OnLoad Examples
Load a Taxonomy in to a model instance
controller.onLoad = function() {
this.parent.onLoad();
var languageTaxonomyInst = loadTaxonomyInstance(siteId, "ctx-core:language", true);
modelContainer.addModel("language-instance", languageTaxonomyInst.dom);
};
OnBeforeSave Examples
Assign a unique/random Filename to the content
controller.onBeforeSave = function(xml, submissionParams) {
this.parent.onBeforeSave(xml, submissionParams);
if (CitrixAuthoring.Utils.isEmpty(xml['file-name'])) {
xml['file-name'] = CitrixAuthoring.Utils.generateUUID() + ".xml";
}
return xml;
};
Remove unwanted markup from a given field
<root> <myFieldSet> <bodyContent>Blah Blah</bodyContent> </myFieldSet> </root>
controller.onBeforeSave = function(xml, submissionParams) {
this.parent.onBeforeSave(xml, submissionParams);
var body = "" + xml.myFieldSet.bodyContent;
body = body.replace(/^<p.*>(.*)<\/p>/gi, "$1");
xml.quoteForm.quote = body;
return xml;
};