Example 19: Prefilling form data
Regarding fetching data from external resources, the specification states:
There are two scenarios where authors may wish data to be fetched from an external file to fill forms. In the first, a select's options are replaced by options from an external file. In the second, a form's values are prefilled from an external data source.
In both cases, the prefilling may either be full, in which case the previous contents are removed first, or incremental, in which case the fetched data is in addition to the data already in the form.
This example/ test suite module is not currently working, because the Javascript code for emulating the data attribute (importing XML data from external sources) has been temporarily removed from the Javascript library, DOM-Repetition.min.js — we might reinstate this functionality in the future.
Filling select
elements
Seeding a form with initial values
The formdata
XML file associated with the following form first clears all of the existing repetition blocks. Then it adds two repetition blocks with indexes 100 and 101. Then it prefills the values of these two repetition blocks.
Setting data
DOM property dynamically on select
elements
The following tests are adapted from an example in the Filling select
elements section.
The eight following select
elements should have exactly the same contents. Note that only the first four will work in Internet Explorer 7.
-
Loading...
Before onload,
data
DOM attribute set on statically created element: -
Loading...
Before onload,
data
content attribute set on statically created element: -
Loading...
Before onload,
select
element dynamically created;data
DOM attribute set: -
Loading...
Before onload,
select
element dynamically created;data
content attribute set withsetAttribute(...)
: -
Loading...
After onload,
data
DOM attribute set on statically created element: -
Loading...
After onload,
data
content attribute set on statically created element: -
Loading...
After onload,
select
element dynamically created;data
DOM attribute set: -
Loading...
After onload,
select
element dynamically created;data
content attribute set withsetAttribute(...)
: