Dependent controls: LoadUrl example implementation
When the value of a field should be dependent on the (selected) value of another field, one way of achieving this is implementing an application page to return the appropriate value and adding custom XForms logic using the xf:modeldata ctfp.
Application page
Add an application page with e.g. code 'LOOKUPFIELD' and SXML logic which determines and sets the appropriate value (see example below).
Contenttype field
Within this example, a contenttype field with a lookuplist is used. So, a contenttype field has been added with the name template (ctspecificvar[x]) with two ctfp's:
- cms:control = "dropdownlist"
- cms:lookuplist = "a:=Template A;b:=Template B;c:=Template C;"
Modeldata
To complete the example, we want to achieve that the body field of an item is changed, dependent on the value that has been selected as template.
To do so, add the ctfp xf:modeldata to the template contenttype field and set its value to something very similar to the example below.
The ev:observer is a reference to the template field (the id of a field always equals its name prefixed with "cf_" and ev:observer must always reference a field id).
So, the first line tells the XForms engine that when the template's field value has changed, the action(s) included within the xf:action tag should be executed.
The xf:setvalue element instructs the XForms engine to set the value of a specific node. Which node needs to be set is specified by its ref attribute.
The value attribute determines the value to be set. In this case, the loadurl extension function is used to call/render the application page (as shown above) and set the returned contents as the value. The url is constructed using the concat XPath function to include the value of the template field within the query string.
Remarks
Notice that you probably need to change the url to match your site's url and default document. Also, ampersands used within the querystring must be escaped as "&".
Within the dashboard manager, the default namespace prefix used for (Smartsite) extension functions is "exf".
The loadurl extension function used within this example is available as of Smartsite 7.9. This extension function only supports requests to unrestricted urls.
The default namespace prefix to reference a field equals "cms".