< XForms

Motivation

You want to load a new resource over your current form.

Usage

In HTML links are simple. You use the HTML anchor tag

<a href="http://example.com">like label</a></nowiki>

However in XForms, it is a bit more complex:

<xf:trigger appearance="minimal">
  <xf:label>Go to Google</xf:label>
  <xf:action ev:event="DOMActivate">
   <xf:load show="replace">
     <xf:resource value="'http://www.google.com'"/>
   </xf:load>
  </xf:action>
</xf:trigger>

The XForms xf:load element has several attributes.

  • ref - a static reference to a single node
  • resource - a static URL such as a relative or absolute URL
  • show - if a new page is created or the current page replaced. Show can have two values: new or replace.
  • target - the target action to be executed

One is the URI of the resource to load and the other is the show attribute. The show attribute can have values of "replace" which will replace the current form with the new resource and "new" which will open a new tab in your web browser or a new window if you are running older browsers such as IE 6.

  <xf:load resource="search.xq" show="new"/>
  <xf:load resource="search.xq" show="replace"/>


xf:load can also be used to run a local javascript function when a form loads:

  <xf:action ev:event="xforms-ready">
   <xf:load resource="javascript:init()"/>
  </xf:action>

Loading Dynamic Strings

Note that the ref attribute of xf:load can only be a static string. You can not change this as the XForms application changes.

If you need to load dynamic string the way to do this is to use the xf:resource element within the xf:load element. The xf:resource element has a value attribute that is used to hold all the dynamic expressions.

For example the following example concats a URL and the search query from an input field.

  <xf:load show="replace">
   <xf:resource value="concat(url, q)"/>
  </xf:load>

Load with resource attribute value templates

Some implementations allow you to dynamically create URLs based on data in our mode.

<xf:load ev:event= "DOMActivate"
 resource= "http://www.google.com/{concat(string(instance('instance')/a), '{', '{{',  string(instance('instance')/b), '}', '}}')}/{{something}}/else">
</xf:load>

Releated XForms Examples

XForms/Search_Using_Load - This example shows how to use a REST search service using the xf:load element XForms/Output_and_Links This example presents the user with a list of links. The user select one from a list and that item is loaded

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.