No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep-0336.xml 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE xep SYSTEM 'xep.dtd' [
  3. <!ENTITY % ents SYSTEM 'xep.ent'>
  4. %ents;
  5. ]>
  6. <?xml-stylesheet type='text/xsl' href='xep.xsl'?>
  7. <xep>
  8. <header>
  9. <title>Data Forms - Dynamic Forms</title>
  10. <abstract>
  11. This specification provides extensions to the data forms model defined in previous XEPs that permit enhanced end-user interaction and
  12. a better user experience. These extensions permit forms to react on user input by permitting the addition, updating or removal of fields in the form
  13. and server-side validation of fields. The extension also defines new states making it possible to display disabled controls,
  14. controls with undefined values or error messages, while still being backwards compatible with the existing data form model with available
  15. extensions.
  16. </abstract>
  17. &LEGALNOTICE;
  18. <number>0336</number>
  19. <status>Deferred</status>
  20. <type>Standards Track</type>
  21. <sig>Standards</sig>
  22. <approver>Council</approver>
  23. <dependencies>
  24. <spec>XMPP Core</spec>
  25. <spec>XEP-0004</spec>
  26. </dependencies>
  27. <supersedes/>
  28. <supersededby/>
  29. <shortname>dynamic-forms</shortname>
  30. &peterwaher;
  31. <revision>
  32. <version>0.2</version>
  33. <date>2015-11-09</date>
  34. <initials>pw</initials>
  35. <remark>
  36. <p>Updated contact information.</p>
  37. <p>Updated example JIDs to example.org</p>
  38. </remark>
  39. </revision>
  40. <revision>
  41. <version>0.1</version>
  42. <date>2014-01-08</date>
  43. <initials>psa</initials>
  44. <remark><p>Initial published version approved by the XMPP Council.</p></remark>
  45. </revision>
  46. <revision>
  47. <version>0.0.4</version>
  48. <date>2013-12-18</date>
  49. <initials>pw</initials>
  50. <remark>
  51. <p>The element formPostBack has been renamed to <strong>submit</strong>.</p>
  52. <p>The element formUpdated has been renamed to <strong>updated</strong>.</p>
  53. <p>The elements formPostBackResponse and cancelResponse have been removed. Error handling has been updated to conform to use IQ error stanzas and error codes.</p>
  54. </remark>
  55. </revision>
  56. <revision>
  57. <version>0.0.3</version>
  58. <date>2013-12-04</date>
  59. <initials>pw</initials>
  60. <remark>
  61. <p>Namespace changed to urn:xmpp:xdata:dynamic.</p>
  62. </remark>
  63. </revision>
  64. <revision>
  65. <version>0.0.2</version>
  66. <date>2013-10-29</date>
  67. <initials>pw</initials>
  68. <remark>
  69. <p>Added comparison to XEP-0050, Ad-hoc commands.</p>
  70. <p>Added support for server push of asynchronous form changes.</p>
  71. <p>Added an implementation note regarding client-side values.</p>
  72. </remark>
  73. </revision>
  74. <revision>
  75. <version>0.0.1</version>
  76. <date>2013-07-23</date>
  77. <initials>pw</initials>
  78. <remark>
  79. <p>First draft.</p>
  80. </remark>
  81. </revision>
  82. </header>
  83. <section1 topic='Introduction' anchor='intro'>
  84. <p>
  85. Data forms are used in many XEPs and provide a mechanism whereby a form can be hosted on one end and displayed on another. XMPP data forms are
  86. defined and enhanced in many different XEPs, as is shown in the following list:
  87. </p>
  88. <ul>
  89. <li>
  90. <p>
  91. &xep0004; defines the basics of data forms: How forms are defined, sent to the recipient, how the recipient submits forms (or cancels them)
  92. and how results can be returned. It defines the concepts of field, field type and field value.
  93. </p>
  94. </li>
  95. <li>
  96. <p>
  97. &xep0122; enhances the data forms architecture permitting rules for client-side validation of fields in the form.
  98. </p>
  99. </li>
  100. <li>
  101. <p>
  102. &xep0137; defines a new data type that can be used to publish file upload controls.
  103. </p>
  104. </li>
  105. <li>
  106. <p>
  107. &xep0141; enhances the data forms architecture permitting the form to have pages or tabs with sections containing grouped controls.
  108. </p>
  109. </li>
  110. <li>
  111. <p>
  112. &xep0221; defines a means to include content such as images, video or audio in forms.
  113. </p>
  114. </li>
  115. <li>
  116. <p>
  117. &xep0331; permits the publication of color fields, where the end user can be presented with a color picker dialog instead of having to
  118. enter a color value manually or select one from a limited list of colors.
  119. </p>
  120. </li>
  121. </ul>
  122. <p>
  123. This specification enhances the data form model further by providing the following features:
  124. </p>
  125. <ul>
  126. <li>
  127. <p>
  128. Form post-back when fields flagged for post-back are edited. This permits the form to adapt itself based on user input, i.e. creating, changing
  129. or removing fields in the form, creating dynamic forms. It also provides a mechanism to publish server-side validation of fields during user input.
  130. </p>
  131. </li>
  132. <li>
  133. <p>
  134. Allows fields to be disabled. They will be shown as normal controls, but in a disabled state. Combining post-back form
  135. fields it is possible to enable and disable (or add or remove) fields depending on user input.
  136. </p>
  137. </li>
  138. <li>
  139. <p>
  140. Allows fields to have not well-defined values. This can be used for instance, when a value is unknown or when multiple objects
  141. are edited at the same time in the same form and the objects have different values for the corresponding field.
  142. </p>
  143. </li>
  144. <li>
  145. <p>
  146. Permits fields to have errors flagged on them. This can be used to give users intuitive feedback on errors in forms. Together
  147. with post-back fields, this provides a mechanism whereby server-side validation of fields can be made while the user is still
  148. editing the form.
  149. </p>
  150. </li>
  151. <li>
  152. <p>
  153. Permits spontaneous updates of the form, pushed from the form server to the client showing the form. This might be necessary in
  154. cases where the process of aquiring current values may take some time, but the client is required to show a form right away.
  155. </p>
  156. </li>
  157. </ul>
  158. <p>
  159. <strong>Note:</strong> This extension is only dependent upon the <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link> XEP. It works in
  160. parallel with any of the above mentioned data form extensions, but do not require that any of them are supported. The examples provided
  161. in this document may still reference extensions made in other documents, but these are considered to be examples only, used to illustrate
  162. a specific point or example.
  163. </p>
  164. <section2 topic='Comparison to Ad-hoc commands'>
  165. <p>
  166. &xep0050; defines a mechanism to enhance data forms creating dialog wizards with actions that guide the user through pages, where each page
  167. can depend on the input from previous pages. The following list consists of a comparison of the differences between Ad-hoc commands and
  168. Dynamic Forms, and why this extension is not based on the concepts defined in XEP-0050:
  169. </p>
  170. <ul>
  171. <li>
  172. <p>
  173. The main point of this extension is to make the current form dynamic. Pages in a wizard, as defined in ad-hoc commands, are still static
  174. requiring page navigation for the dialog to be updated.
  175. </p>
  176. </li>
  177. <li>
  178. <p>
  179. There might be a desire to make individual pages inside a wizard dynamic by themselves. In this case, this extension might be used to
  180. extend Ad-hoc commands with dynamic pages inside wizards.
  181. </p>
  182. </li>
  183. <li>
  184. <p>
  185. Wizards order their pages linearly, in a one-dimensional array of pages. Navigation is only performed using prev and next actions, and completed with the execute or
  186. complete actions. This might work sufficiently well where page output only is based on input from the previous page. But as soon as the input depends on more pages,
  187. navigation becomes unnecessarily cumbersome. For example a dialog with country, region, city, area, street, building, apartment. To change the country parameter when you
  188. are on the apartment page, requires you to back through many pages, while in the dynamic form you just change the parameter directly, since all are visible
  189. in the same form.
  190. </p>
  191. <p>
  192. The problem gets worse if this is a normal behavior for a form. Say a dialog with a post carrier field, followed by country, city, office, etc.
  193. When the user comes to office and notices that the selected carrier has no office close to you, you change carrier, but don't want to change country and city, if
  194. possible.
  195. </p>
  196. </li>
  197. <li>
  198. <p>
  199. The pages in a wizard do not allow for spontaneous or immediate feedback to the user. Such immediate feedback is of great importance in user-friendly
  200. forms, where complex input is required. Consider the following simple example:
  201. </p>
  202. <p>
  203. Imagine a dialog used for configuring a TCP port scanner to search for specific devices in a network. It might take five parameters: IP range, port range, number of threads,
  204. connection timeout (ms) and number of tries before failing. However, the operator wants to know how much time the operation will take (which is #IP-addresses *
  205. #port numbers * Connection Timeout * Nr Tries / #Threads). To see this in a separate page and then have to go back to the different pages, forwarding to the
  206. time estimate calculation page, etc., is a very cumbersome process. Presenting all this information on a single page using Dynamic Forms is creates a much
  207. better and richer user experience. Changing the value of any of the five parameters will directly update a text parameter presenting the total expected time of the
  208. operation.
  209. </p>
  210. </li>
  211. <li>
  212. <p>
  213. Wizards as defined in Ad-hoc commands are hard-wired to commands as such. Navigation actions are defined outside of the scope of the form itself. This extensions
  214. defines Dynamic Forms as an extension of the Data Form concept. All navigation, post-back fields, etc., are defined within the actual form itself. This makes
  215. it re-usable everywhere data forms are used, including pages inside an Ad-Hoc command wizard.
  216. </p>
  217. </li>
  218. <li>
  219. <p>
  220. Ad-hoc command wizards include the feature to return notes including information, warnings or error information to the user. This information however, is associated
  221. with the current page in the wizard itself. Dynamic Forms contains a means to attach error information directly to individual fields, making feedback more precise.
  222. Together with the server post-back feature immediate server-side validation during user input is possible.
  223. </p>
  224. </li>
  225. <li>
  226. <p>
  227. Dynamic Forms contains a feature that ad-hoc command wizards do not: Read-only fields. These differs from other text fields in that they are rendered as normal
  228. controls, except input is read-only. Together with the server post-back feature this allows the server to enable and disable parameters depending on user
  229. input on the same page. An example can be a checkbox that enabled another field if checked, as a security measure.
  230. </p>
  231. </li>
  232. <li>
  233. <p>
  234. Dynamic Forms defines the concept of an undefined field value. These fields are presented with the available value (if any), but greyed out, signaling to the user that
  235. the value is not well defined for some reason. Perhaps it is only one of many values held my multiple objects in the case when editing multiple objects at once.
  236. Undefined values are not sent back to the server when the form is posted back. When the user edits such a field, the undefined flag is cleared and the field is
  237. presented as a normal control. The main purpose of this flag is to allow for editing multiple objects at once or for editing control forms where current states are
  238. not known at the moment if creating the form.
  239. </p>
  240. </li>
  241. <li>
  242. <p>
  243. Dynamic Forms supports asynchronous updates of the form, where the server can push changes to the form not resulting from user input. This is a powerful feature that
  244. allows the server to update a form being edited by the user to reflect changes on the server. Consider the following examples:
  245. </p>
  246. <p>
  247. Consider a control form containing control fields on a remote device. At the time of displaying the form, the current states of some fields might be unknown. So the fields
  248. are marked perhaps with some default values, but with the undefined flag set for the corresponding fields. At the time of creating the form, a parallel request is made
  249. to the device by the form server, requesting information about current states of the device. When these are received by the server, it issues an update of the form to the
  250. client with the newly received and current field values. The request for values might take some time, so using this mechanism provides a form to the user quickly, clearly
  251. indicating what is missing, and then complements the form when data is available.
  252. </p>
  253. <p>
  254. Another example might be a dialog showing contents on the form server in a multi-user environment where updates to the contents is made. An example can be a file system.
  255. If changes to the contents is made by another user, the server has the possibility to update any current forms to reflect changes made. This decreases the possibility
  256. of inconsistencies in the system, and at the same time increases the user-friendliness of the end-user experience of the application.
  257. </p>
  258. </li>
  259. </ul>
  260. </section2>
  261. </section1>
  262. <section1 topic='Glossary' anchor='glossary'>
  263. <p>The following table lists terms and corresponding descriptions or definitions for use throughout this document.</p>
  264. <dl>
  265. <di>
  266. <dt>Control</dt>
  267. <dd>
  268. The visual control used to display a <strong>field</strong>.
  269. </dd>
  270. </di>
  271. <di>
  272. <dt>Data Form</dt>
  273. <dd>
  274. A form of parameters (a.k.a. fields), as defined in <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link>.
  275. </dd>
  276. </di>
  277. <di>
  278. <dt>Field</dt>
  279. <dd>
  280. A field representing a parameter or control, in a data form, as defined in <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link>.
  281. </dd>
  282. </di>
  283. <di>
  284. <dt>Form Client</dt>
  285. <dd>
  286. For simplicity, we will call the XMPP client that fills in the data form, the <strong>form client</strong>.
  287. </dd>
  288. </di>
  289. <di>
  290. <dt>Form Server</dt>
  291. <dd>
  292. For simplicity, we will call the XMPP client that hosts a data form, the <strong>form server</strong>.
  293. </dd>
  294. </di>
  295. <di>
  296. <dt>Parameter</dt>
  297. <dd>
  298. Used sometimes synonymously with <strong>field</strong>.
  299. </dd>
  300. </di>
  301. </dl>
  302. </section1>
  303. <section1 topic='Use Cases' anchor='usecases'>
  304. <p>
  305. The following subsections list use cases for the different enhancements defined by this extension. Elements are defined using the namespace
  306. <strong>urn:xmpp:xdata:dynamic</strong> and namespace prefix <strong>xdd</strong>.
  307. </p>
  308. <section2 topic='Publishing post-back fields'>
  309. <p>
  310. Post-back fields are fields that require the client to post the form to the server after being edited. This permits the server
  311. to perform server-side validation on the field, provide immediate user feed-back and change the form according to user input.
  312. </p>
  313. <p>
  314. Post-back fields are declared as normal fields in a form, except they also have the <strong>xdd:postBack</strong> flag present in
  315. the declaration, as is shown in the following example:
  316. </p>
  317. <example caption='Publishing post-back fields'>
  318. <![CDATA[
  319. <x xmlns="jabber:x:data" type="form"
  320. xmlns:xdd="urn:xmpp:xdata:dynamic"
  321. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  322. <title>Current location</title>
  323. <instructions>Select your current location to continue.</instructions>
  324. <field var='xdd session' type='hidden'>
  325. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  326. </field>
  327. <field var="Country_ISO_3166_1" type="list-single" label="Country:">
  328. <desc>Select your country of residence.</desc>
  329. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:string">
  330. <xdv:basic/>
  331. </xdv:validate>
  332. <value/>
  333. <xdd:postBack/>
  334. <option label="Chile">
  335. <value>CL</value>
  336. </option>
  337. <option label="Sweden">
  338. <value>SE</value>
  339. </option>
  340. <option label="United States">
  341. <value>US</value>
  342. </option>
  343. ...
  344. </field>
  345. </x>]]>
  346. </example>
  347. <p>
  348. <strong>Note:</strong> A system maintaining multiple dynamic forms open at the same time needs to maintain control
  349. of available open forms. This can be done using a hidden session variable, as is shown in the example above. How this
  350. is done however, is implementation specific.
  351. </p>
  352. </section2>
  353. <section2 topic='Performing a server post-back'>
  354. <p>
  355. A server post-back is performed by sending an IQ set stanza with a <strong>submit</strong> child element containing the
  356. current state of the form. The type of the form must be <strong>submit</strong>. The client should also provide the current
  357. user language in a <strong>xml:lang</strong> attribute, if available.
  358. </p>
  359. <example caption='Performing a server post-back'>
  360. <![CDATA[
  361. <iq type='set'
  362. from='formclient@example.org/client'
  363. to='formserver@example.org'
  364. id='1'>
  365. <submit xmlns='urn:xmpp:xdata:dynamic' xml:lang='en'>
  366. <x xmlns="jabber:x:data" type="submit">
  367. <field var='xdd session'>
  368. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  369. </field>
  370. <field var="Country_ISO_3166_1">
  371. <value>CL</value>
  372. </field>
  373. </x>
  374. </submit>
  375. </iq>]]>
  376. </example>
  377. <p>
  378. It is important to note that this server post-back is part of editing the form, and must not be treated by the server as a final
  379. submission of the data form.
  380. </p>
  381. <p>
  382. As a response to a successful form post-back, the server returns the new data form, as is shown in the following example:
  383. </p>
  384. <example caption='Post-back response'>
  385. <![CDATA[
  386. <iq type='result'
  387. from='formserver@example.org'
  388. to='formclient@example.org/client'
  389. id='1'>
  390. <x xmlns="jabber:x:data" type="form"
  391. xmlns:xdd="urn:xmpp:xdata:dynamic"
  392. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  393. <title>Current location</title>
  394. <instructions>Select your current location to continue.</instructions>
  395. <field var='xdd session' type='hidden'>
  396. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  397. </field>
  398. <field var="Country_ISO_3166_1" type="list-single" label="Country:">
  399. <desc>Select your country of residence.</desc>
  400. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:string">
  401. <xdv:basic/>
  402. </xdv:validate>
  403. <value>CL</value>
  404. <xdd:postBack/>
  405. <option label="Chile">
  406. <value>CL</value>
  407. </option>
  408. <option label="Sweden">
  409. <value>SE</value>
  410. </option>
  411. <option label="United States">
  412. <value>US</value>
  413. </option>
  414. ...
  415. </field>
  416. <field var="Region_ISO_3166_2" type="list-single" label="Region:">
  417. <desc>Select your region of residence.</desc>
  418. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:string">
  419. <xdv:basic/>
  420. </xdv:validate>
  421. <value/>
  422. <xdd:postBack/>
  423. <option label="Antofagasta">
  424. <value>AN</value>
  425. </option>
  426. <option label="Arica y Parinacota">
  427. <value>AP</value>
  428. </option>
  429. <option label="Atacama">
  430. <value>AT</value>
  431. </option>
  432. ...
  433. </field>
  434. </x>
  435. </iq>]]>
  436. </example>
  437. <p>
  438. In this example, the server adds a new parameter to the form, containing options that depend on the value of the first parameter.
  439. </p>
  440. <p>
  441. <strong>Note:</strong> Server post-back should be made after the user is done editing a post-back field, but before actually navigating to the
  442. next field. It should not be done while the user is editing the field. For check boxes or list boxes, it is easy for the application
  443. to decide when the field has been edited, since the application can react to the controls click event. But for text edit boxes, you
  444. cannot perform a server post-back only just because the text property of the control has changed. You need to wait until the user
  445. leaves the control or something similar. However, as new fields can be added to the form, the client should wait for the response
  446. before deciding which control is the next control to go to.
  447. </p>
  448. </section2>
  449. <section2 topic='Publishing read-only fields'>
  450. <p>
  451. Read-only fields should be laid out on the form just as a similar but editable field would, except editing should be disabled. Together with
  452. post-back fields, this option allows the form to enable/disable fields depending on user input. Read-only fields are declared as normal fields
  453. in a form, except they also have the <strong>xdd:readOnly</strong> flag present in the declaration, as is shown in the following example:
  454. </p>
  455. <example caption='Publishing read-only fields'>
  456. <![CDATA[
  457. <x xmlns="jabber:x:data" type="form"
  458. xmlns:xdd="urn:xmpp:xdata:dynamic"
  459. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  460. <title>Object properties</title>
  461. <field var='xdd session' type='hidden'>
  462. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  463. </field>
  464. <field var="ID" type="text-single" label="ID:">
  465. <desc>ID of object.</desc>
  466. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:string">
  467. <xdv:basic/>
  468. </xdv:validate>
  469. <value>Object 1</value>
  470. <xdd:readOnly/>
  471. </field>
  472. <field var="RenameID" type="boolean" label="Rename object">
  473. <desc>To avoid accidental renaming of the objcet, this box must be checked to rename the object.</desc>
  474. <value>0</value>
  475. <xdd:postBack/>
  476. </field>
  477. ...
  478. </x>]]>
  479. </example>
  480. <p>
  481. <strong>Note:</strong> Using this flag is different from the field type <strong>fixed</strong> defined in
  482. <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link>. Fields of type <strong>fixed</strong>
  483. can also be used to display read-only content. However, this is done as static text, and not as a disabled
  484. control, specific for the type of content corresponding to the data in question. Using the <strong>readOnly</strong>
  485. flag instead, gives greater flexibility when it comes to presentation, as well as permitting the form server
  486. to enable and disable controls during the lifetime of the form.
  487. </p>
  488. <p>
  489. <strong>Note 2:</strong> Make sure to check the implementation note <link url='#clientsidevalues'>Merging Client-Side Values</link> for information
  490. on how to merge updates received from the server with current input made by the client.
  491. </p>
  492. </section2>
  493. <section2 topic='Publishing fields with undefined values'>
  494. <p>
  495. There are many cases where you want to flag a control as having an <strong>undefined value</strong> or an
  496. <strong>uncertain</strong> value, instead of simply a missing value. This permits the form client to display the
  497. control in a specific way (for instance greyed), and omit the field when submitting the form back to the server,
  498. to avoid errors.
  499. </p>
  500. <p>
  501. This technique can be used for instance, when editing the properties of multiple objects at the same time. Attributes
  502. that are equal among the objects can be reported as normal fields, while attributes that have different values among
  503. the objects, can be reported as having a value that is not the same everywhere. The client can then show the
  504. corresponding control greyed and omitting it in submissions of the form. If the user edits the control however, the
  505. form client can remove the flag and render the control normally. Submitting the now well-defined field value will
  506. set the corresponding attribute in all objects to the same new value. Omitting undefined values makes sure that
  507. the corresponding attributes are left as-is.
  508. </p>
  509. <p>
  510. Fields with undefined or uncertain values are declared as normal fields in a form, except they also have the
  511. <strong>xdd:notSame</strong> flag present in the declaration, as is shown in the following example:
  512. </p>
  513. <example caption='Publishing fields with undefined values'>
  514. <![CDATA[
  515. <x xmlns="jabber:x:data" type="form"
  516. xmlns:xdd="urn:xmpp:xdata:dynamic"
  517. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  518. <title>Communication properties</title>
  519. <field var='xdd session' type='hidden'>
  520. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  521. </field>
  522. <field var="Address" type="text-single" label="Bus Address:">
  523. <desc>Enter the bus address of the device.</desc>
  524. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:int">
  525. <xdv:range min="1" max="250"/>
  526. </xdv:validate>
  527. <value>1</value>
  528. <xdd:notSame/>
  529. </field>
  530. <field var="BaudRate" type="list-single" label="Baud rate:">
  531. <desc>Baud rate to use when communicating with the device.</desc>
  532. <value>2400</value>
  533. <option label='300 baud'><value>300</value></option>
  534. <option label='2400 baud'><value>2400</value></option>
  535. </field>
  536. ...
  537. </x>]]>
  538. </example>
  539. <p>
  540. In the above example communication properties of a set of objects are edited. The form contains two fields, one address field, which will contain
  541. unique values for each individual object and therefore be flagged with the <strong>xdd:notSame</strong> flag, and
  542. a second baud rate field. This second field will probably contain the same value, if devices are connected to the
  543. same bus. Therefore, the field value is not flagged with the <strong>xdd:notSame</strong> flag.
  544. </p>
  545. <p>
  546. <strong>Note:</strong> If the <strong>xdd:notSame</strong> flag is available in a field, the field must not be
  547. flagged as being <strong>required</strong>. They must also be omitted in any form submissions unless they have been
  548. edited first. Furthermore, any field submitted in a post-back as described in this document, must not be returned
  549. in the post-back response having the <strong>xdd:notSame</strong> flag.
  550. </p>
  551. <p>
  552. Notice also that there's a difference between a missing value, i.e. a field without a <strong>value</strong> element defined, and
  553. a field with a <strong>value</strong> defined, but with the <strong>xdd:notSame</strong> flag present. In the latter example,
  554. the value might represent the value of one of the objects in a set of objects being edited.
  555. </p>
  556. </section2>
  557. <section2 topic='Publishing fields containing errors'>
  558. <p>
  559. A field can be flagged with an error message using the <strong>xdd:error</strong> element. Together with the post-back feature this allows
  560. for more advanced server-side validation of field values, as is shown in the following example.
  561. </p>
  562. <example caption='Publishing fields with undefined values'>
  563. <![CDATA[
  564. <x xmlns="jabber:x:data" type="form"
  565. xmlns:xdd="urn:xmpp:xdata:dynamic"
  566. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  567. <title>Expression</title>
  568. <field var='xdd session' type='hidden'>
  569. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  570. </field>
  571. <field var="Expression" type="text-single" label="Expression:">
  572. <desc>Enter the expression you want to plot.</desc>
  573. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:string">
  574. <xdv:basic/>
  575. </xdv:validate>
  576. <value>sin(x</value>
  577. <xdd:postBack/>
  578. <xdd:error>Unexpected end of expression. ) expected.</xdd:error>
  579. </field>
  580. ...
  581. </x>]]>
  582. </example>
  583. <p>
  584. In the above example, the user can enter a script expression into a text box using a server-specific scripting language.
  585. There's no way for the client to validate the script expression. However, by flagging the field with <strong>xdd:postBack</strong>
  586. the client posts the form back to the server when the user is finished writing the expression, and the server can validate it.
  587. In the example, the user has made an error, and the server returns the field, with an <strong>xdd:error</strong> flag, containing
  588. an error message that can be displayed to the user in an appropriate way.
  589. </p>
  590. <p>
  591. <strong>Note:</strong> If a field is flagged with an error, and the user starts editing it, the client should remove the error
  592. flag of the field. The field can be flagged again with a new error flag during the next post-back.
  593. </p>
  594. </section2>
  595. <section2 topic='Cancelling a dynamic form'>
  596. <p>
  597. The <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link> XEP provides a mechanism to cancel forms, by submitting the
  598. form using <strong>type='cancel'</strong>. The <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link> XEP stipulates that
  599. fields should not be included when using the form type cancel. However dynamic forms, i.e. forms containing post-back fields, will need
  600. the fields, since any dynamic form session will be identified using hidden fields in the form. So, to cancel a dynamic form, the
  601. <strong>xdd:cancel</strong> element with the entire submitted form should be sent to the form server using an IQ set stanza, as is shown
  602. in the following example:
  603. </p>
  604. <example caption='Cancelling a dynamic form'>
  605. <![CDATA[
  606. <iq type='set'
  607. from='formclient@example.org/client'
  608. to='formserver@example.org'
  609. id='4'>
  610. <cancel xmlns='urn:xmpp:xdata:dynamic'>
  611. <x xmlns="jabber:x:data" type="submit">
  612. <field var='xdd session'>
  613. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  614. </field>
  615. ...
  616. </x>
  617. </cancel>
  618. </iq>]]>
  619. </example>
  620. <p>
  621. After receiving the cancel request the form server returns an empty response if the form was found (and therefore cancelled), or an
  622. IQ error stanza with an <strong>item-not-found</strong> error if the form was not found. The following example shows a response where
  623. the form was found and cancelled:
  624. </p>
  625. <example caption='Dynamic form cancelled'>
  626. <![CDATA[
  627. <iq type='result'
  628. from='formserver@example.org'
  629. to='formclient@example.org/client'
  630. id='4'/>]]>
  631. </example>
  632. <p>
  633. <strong>Note:</strong> If cancelling a dynamic form using the approach described in this document, there's no need to also submit
  634. a cancel form as defined in the <link url='http://xmpp.org/extensions/xep-0004.html'>Data Forms</link> XEP. The form server automatically
  635. makes sure the form is cancelled in all instances on the form server.
  636. </p>
  637. <p>
  638. <strong>Note 2:</strong> If the dynamic form is invoked from a specific operation that includes its own cancel procedure, like
  639. Ad-hoc command sessions, the dynamic form is automatically and implicitly cancelled if the corresponding operation is cancelled.
  640. There is no need to explicitly cancel the dynamic form as explained in this section in such cases.
  641. </p>
  642. </section2>
  643. <section2 topic='Dynamic form not found during post-back'>
  644. <p>
  645. It might happen that the form server does not find the dynamic form posted by the form client during a post back. Reasons for this can be
  646. that the form does not include a post-back field, or that a form session timeout has occurred and the form server has discarded the dynamic
  647. form to avoid memory leaks. Regardless of the reason, the form server responds using an IQ error stanza with the <strong>item-not-found</strong>
  648. error, when the client posts a form that is not found back.
  649. </p>
  650. <example caption='Dynamic form not found during post-back'>
  651. <![CDATA[
  652. <iq type='error'
  653. from='formserver@example.org'
  654. to='formclient@example.org/client'
  655. id='2'>
  656. <error type='cancel'>
  657. <item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  658. </error>
  659. </iq>]]>
  660. </example>
  661. <p>
  662. <strong>Note:</strong> Form post-back must only be performed on forms containing post-back fields. The form server
  663. is not required to maintain dynamic form sessions for forms that lack post-back fields.
  664. </p>
  665. </section2>
  666. <section2 topic='Other error during post-back'>
  667. <p>
  668. If another error occurs during post-back, the form server can inform the client about this by using the relevant error element and
  669. provide further information in a <strong>text</strong> element to describe the error, as is shown in the following example:
  670. </p>
  671. <example caption='Other error during post-back'>
  672. <![CDATA[
  673. <iq type='error'
  674. from='formserver@example.org'
  675. to='formclient@example.org/client'
  676. id='3'>
  677. <error type='cancel'>
  678. <internal-server-error xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
  679. <text>An internal error occurred: Stack limit has been reached.</text>
  680. </error>
  681. </iq>]]>
  682. </example>
  683. </section2>
  684. <section2 topic='Asynchronous updates of forms (server push)'>
  685. <p>
  686. The server may send asynchronous updates to open forms on the client. This can be done if the server detects changes that it wants to inform
  687. the client about. Changes are made by sending a <strong>message</strong> stanza including a <strong>updated</strong> element which in turn
  688. contains the new updated form.
  689. </p>
  690. <p>
  691. Examples can include a control form showing control parameters. While the server is trying to retrieve the current values
  692. it presents the control form with undefined values, and later when values are received by the server, it sends an update to the client with
  693. actual values.
  694. </p>
  695. <p>
  696. Another example can include a dialog containing information on items on the server in a multi-user environment (for instance a file system).
  697. Changes made by users can be displayed in open dialogs to other users as they change.
  698. </p>
  699. <p>
  700. The client may have more than one form open at any given time. It might also be so that the form has been closed prior to receiving or handling the update message,
  701. and is therefore no longer visible. To be able to identify to which form the update corresponds, the <strong>updated</strong>
  702. element is required to include a <strong>sessionVariable</strong> attribute in which it identifies a <strong>unique</strong> identifying
  703. field in the form. When the client receives the update, it goes through all forms it has open. If a form has a field variable with a corresponding
  704. name, and the field variable has a value equal to the value in the updated form, the form should be updated by the contents of the message. If no form is found,
  705. the update is simply ignored. If multiple forms are found, all should be updated.
  706. </p>
  707. <example caption='Asynchronous update of form (server push)'>
  708. <![CDATA[
  709. <x xmlns="jabber:x:data" type="form"
  710. xmlns:xdd="urn:xmpp:xdata:dynamic"
  711. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  712. <title>Control parameters</title>
  713. <field var='xdd session' type='hidden'>
  714. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  715. </field>
  716. <field var="AnalogOutput" type="text-single" label="Analog Output:">
  717. <desc>Enter a new value for the analog output.</desc>
  718. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:int">
  719. <xdv:range min="0" max="65535"/>
  720. </xdv:validate>
  721. <value>0</value>
  722. <xdd:notSame/>
  723. </field>
  724. </x>
  725. ...
  726. <message from='server@example.org'
  727. to='client@example.org/client'>
  728. <updated xmlns='urn:xmpp:xdata:dynamic' sessionVariable='xdd session' xml:lang='en'>
  729. <x xmlns="jabber:x:data" type="form"
  730. xmlns:xdd="urn:xmpp:xdata:dynamic"
  731. xmlns:xdv="http://jabber.org/protocol/xdata-validate">
  732. <title>Control parameters</title>
  733. <field var='xdd session' type='hidden'>
  734. <value>009c7956-001c-43fb-8edb-76bcf74272c9</value>
  735. </field>
  736. <field var="AnalogOutput" type="text-single" label="Analog Output:">
  737. <desc>Enter a new value for the analog output.</desc>
  738. <xdv:validate xmlns:xdv="http://jabber.org/protocol/xdata-validate" datatype="xs:int">
  739. <xdv:range min="0" max="65535"/>
  740. </xdv:validate>
  741. <value>49152</value>
  742. </field>
  743. </x>
  744. </updated>
  745. </message>]]>
  746. </example>
  747. <p>
  748. <strong>Note:</strong> Make sure to check the implementation note <link url='#clientsidevalues'>Merging Client-Side Values</link> for information
  749. on how to merge updates received from the server with current input made by the client.
  750. </p>
  751. <p>
  752. <strong>Note 2:</strong> The client should also provide the current user language in a <strong>xml:lang</strong> attribute in the <strong>updated</strong>
  753. element, if available, as is shown in the example above.
  754. </p>
  755. </section2>
  756. </section1>
  757. <section1 topic='Determining Support' anchor='support'>
  758. <p>If an entity supports the protocol specified herein, regardless if the entity represents a form server or a form client; it MUST advertise
  759. that fact by returning a feature of "urn:xmpp:xdata:dynamic" in response to &xep0030; information requests.</p>
  760. <example caption="Service discovery information request">
  761. <![CDATA[
  762. <iq type='get'
  763. from='formclient@example.org/client'
  764. to='formserver@example.org'
  765. id='disco1'>
  766. <query xmlns='http://jabber.org/protocol/disco#info'/>
  767. </iq>]]>
  768. </example>
  769. <example caption="Service discovery information response">
  770. <![CDATA[
  771. <iq type='result'
  772. from='formserver@example.org'
  773. to='formclient@example.org/client'
  774. id='disco1'>
  775. <query xmlns='http://jabber.org/protocol/disco#info'>
  776. ...
  777. <feature var='urn:xmpp:xdata:dynamic'/>
  778. ...
  779. </query>
  780. </iq>]]>
  781. </example>
  782. <p>
  783. In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined
  784. in &xep0115;. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.
  785. </p>
  786. </section1>
  787. <section1 topic='Implementation Notes' anchor='impl'>
  788. <section2 topic='Dynamic Form Sessions'>
  789. <p>
  790. For a form server to maintain the status of the dynamic form, it will probably need to publish state or session
  791. information using hidden fields in the dynamic form. It's important that form clients be aware that such hidden
  792. fields are available and must always return them in all submissions of the form to the server.
  793. </p>
  794. <p>
  795. A form client that supports dynamic forms and opens a dynamic form, i.e. containing parameters requiring post-back,
  796. must call the specific <strong>cancel</strong> method described in this document to cancel the form if not
  797. submitted. This to let the form server to release any dynamic form session resources it maintains.
  798. </p>
  799. <p>
  800. <strong>Note:</strong> When submitting a dynamic form the normal way, any dynamic form session resources are also
  801. automatically released.
  802. </p>
  803. </section2>
  804. <section2 topic='Session Timeouts'>
  805. <p>
  806. The form server must be aware that some form clients do not support dynamic forms. This in turn implies that form clients
  807. may not call the correct cancel method to cancel a dynamic form. To protect the form server from memory leaks, it must
  808. include a session timeout, and release any dynamic form session resources if no activity has been made during the
  809. corresponding time period. If the client would perform a post-back after the timeout period, an <strong>item-not-found</strong>
  810. error message must be returned, to show the corresponding dynamic form session no longer exists, and therefore could
  811. not be found.
  812. </p>
  813. <p>
  814. For normal operations, a dynamic form session timeout of 15 minutes is sufficient.
  815. </p>
  816. </section2>
  817. <section2 topic='Merging Client-Side Values' anchor='clientsidevalues'>
  818. <p>
  819. When receiving asynchronous form updates from the server, or when performing a server post-back of a form, it is important
  820. to know how to merge responses from the server with the current form being displayed to the user. As the operation is
  821. asynchronous, and since user input is quick, the user might have input things not known to the server and therefore not
  822. available in form updates. Also, fields not marked for post-back might not have been reported at all to the server, and
  823. therefore, the client is the only one that knows what the user has entered into these fields.
  824. </p>
  825. <p>
  826. So, when receiving form updates, either asynchronously, or as part of a server post-back response, the client needs to merge
  827. the updated form, with the current form. The following rules must be applied. Here, the <strong>updated form</strong> represents the
  828. form in the recent message from the server, the <strong>current form</strong> represents the form currently being edited by the user
  829. and the <strong>resulting form</strong> represents the result of the merger of the updated form and the current form.
  830. </p>
  831. <ul>
  832. <li>
  833. <p>
  834. New fields in the updated form not available in the <strong>current form</strong>, are added as-is to the <strong>resulting form</strong>.
  835. </p>
  836. </li>
  837. <li>
  838. <p>
  839. Fields not available in the <strong>updated form</strong> but available in the <strong>current form</strong>, must be removed from the
  840. <strong>resulting form</strong> regardless if user input is available. Any such user input is lost.
  841. </p>
  842. </li>
  843. <li>
  844. <p>
  845. The order of fields in the resulting form must be the same as the order of fields in the <strong>updated form</strong>.
  846. </p>
  847. </li>
  848. <li>
  849. <p>
  850. Fields available in both the <strong>updated form</strong> and the <strong>current form</strong> are handled depending on if the user has entered
  851. values in the corresponding field in the <strong>current form</strong> or not:
  852. </p>
  853. <ul>
  854. <li>
  855. If the user has <strong>not</strong> edited the value in the corresponding field, the value from the <strong>updated form</strong> is used.
  856. </li>
  857. <li>
  858. If the user has edited the value the corresponding field, the value from the <strong>current form</strong> is used.
  859. </li>
  860. <li>
  861. If the user has edited the value of the corresponding field in the <strong>current form</strong>, but the value is the same as the value
  862. available in the <strong>updated form</strong>, the flag stating that user input has occurred in the field can be cleared.
  863. </li>
  864. </ul>
  865. </li>
  866. <li>
  867. <p>
  868. If a field in the <strong>updated form</strong> is flagged as <strong>undefined</strong>, but the <strong>current form</strong> has an edited value,
  869. the form in the <strong>resulting form</strong> must <strong>not</strong> be marked as <strong>undefined</strong>.
  870. </p>
  871. </li>
  872. <li>
  873. <p>
  874. All other properties for fields must be taken from the <strong>updated form</strong> and copied to the <strong>resulting form</strong>.
  875. </p>
  876. </li>
  877. </ul>
  878. <p>
  879. How the above merger is made is implementation specific. One simple implementation can simply be taking the updated form, adding any client-side values to it
  880. (i.e. values edited in the current form) perhaps removing any undefined value flags, and then use the result as a model for the resulting form.
  881. </p>
  882. </section2>
  883. </section1>
  884. <section1 topic='Security Considerations' anchor='security'>
  885. <p>
  886. There are no security concerns related to this specification above, beyond those described in the relevant section of <strong>XMPP Core</strong>.
  887. </p>
  888. </section1>
  889. <section1 topic='IANA Considerations' anchor='iana'>
  890. <p>This document requires no interaction with &IANA;.</p>
  891. </section1>
  892. <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  893. <p>
  894. The <link url="#schema">protocol schema</link> needs to be added to the list of <link url="http://xmpp.org/resources/schemas/">XMPP protocol schemas</link>.
  895. </p>
  896. </section1>
  897. <section1 topic='XML Schema' anchor='schema'>
  898. <code>
  899. <![CDATA[
  900. <?xml version='1.0' encoding='UTF-8'?>
  901. <xs:schema
  902. xmlns:xs='http://www.w3.org/2001/XMLSchema'
  903. targetNamespace='urn:xmpp:xdata:dynamic'
  904. xmlns='urn:xmpp:xdata:dynamic'
  905. xmlns:xd="jabber:x:data"
  906. elementFormDefault='qualified'>
  907. <xs:import namespace='jabber:x:data'/>
  908. <xs:element name='postBack'>
  909. <xs:annotation>
  910. <xs:documentation>Flags a field as requiring server post-back after having been edited.</xs:documentation>
  911. </xs:annotation>
  912. <xs:complexType/>
  913. </xs:element>
  914. <xs:element name='readOnly'>
  915. <xs:annotation>
  916. <xs:documentation>Flags a field as being read-only.</xs:documentation>
  917. </xs:annotation>
  918. <xs:complexType/>
  919. </xs:element>
  920. <xs:element name='notSame'>
  921. <xs:annotation>
  922. <xs:documentation>Flags a field as having an undefined or uncertain value.</xs:documentation>
  923. </xs:annotation>
  924. <xs:complexType/>
  925. </xs:element>
  926. <xs:element name='error'>
  927. <xs:annotation>
  928. <xs:documentation>Flags a field as having an error.</xs:documentation>
  929. </xs:annotation>
  930. <xs:simpleType>
  931. <xs:restriction base='xs:string'/>
  932. </xs:simpleType>
  933. </xs:element>
  934. <xs:element name='submit'>
  935. <xs:complexType>
  936. <xs:sequence>
  937. <xs:element ref='xd:x' minOccurs='1' maxOccurs='1'/>
  938. </xs:sequence>
  939. </xs:complexType>
  940. </xs:element>
  941. <xs:element name='updated'>
  942. <xs:complexType>
  943. <xs:sequence>
  944. <xs:element ref='xd:x' minOccurs='1' maxOccurs='1'/>
  945. </xs:sequence>
  946. <xs:attribute name='sessionVariable' type='xs:string' use='required'/>
  947. </xs:complexType>
  948. </xs:element>
  949. <xs:element name='cancel'>
  950. <xs:complexType>
  951. <xs:sequence>
  952. <xs:element ref='xd:x' minOccurs='1' maxOccurs='1'/>
  953. </xs:sequence>
  954. </xs:complexType>
  955. </xs:element>
  956. </xs:schema>]]>
  957. </code>
  958. </section1>
  959. <section1 topic='Acknowledgements' anchor='ack'>
  960. <p>Thanks to Karin Forsell and Lance Stout for all valuable feedback.</p>
  961. </section1>
  962. </xep>