Skip to content

Conversation

@garethbowen
Copy link
Collaborator

Closes #122

I have verified this PR works in these browsers (latest versions):

  • Chrome
  • Firefox
  • Safari (macOS)
  • Safari (iOS)
  • Chrome for Android
  • Not applicable

What else has been done to verify that this works as intended?

Testing.

Why is this the best possible solution? Were any other approaches considered?

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Introduces new functionality.

Do we need any specific form for testing your changes? If so, please attach one.

From this PR: packages/common/src/fixtures/test-javarosa/resources/preload.xml

<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa">
    <h:head>
        <h:title>jr:preload</h:title>
        <model>
            <instance>
                <data id="preload" version="1">
                    <today/>
                    <start/>
                    <end/>
                    <deviceid/>
                    <phonenumber/>
                    <email/>
                    <username/>
                    <meta>
                        <instanceID/>
                    </meta>
                </data>
            </instance>
            <bind jr:preload="date" jr:preloadParams="today" nodeset="/data/today" type="date" readonly="true()"/>
            <bind jr:preload="timestamp" jr:preloadParams="start" nodeset="/data/start" type="dateTime" readonly="true()"/>
            <bind jr:preload="timestamp" jr:preloadParams="end" nodeset="/data/end" type="dateTime" readonly="true()"/>
            <bind jr:preload="property" jr:preloadParams="deviceid" nodeset="/data/deviceid" type="string" readonly="true()"/>
            <bind jr:preload="property" jr:preloadParams="phonenumber" nodeset="/data/phonenumber" type="string" readonly="true()"/>
            <bind jr:preload="property" jr:preloadParams="email" nodeset="/data/email" type="string" readonly="true()"/>
            <bind jr:preload="property" jr:preloadParams="username" nodeset="/data/username" type="string" readonly="true()"/>
            <bind jr:preload="uid" nodeset="/data/meta/instanceID" type="string" readonly="true()"/>
        </model>
    </h:head>
    <h:body>
        <input ref="/data/today">
            <label>today</label>
        </input>
        <input ref="/data/start">
            <label>start</label>
        </input>
        <input ref="/data/end">
            <label>end</label>
        </input>
        <input ref="/data/deviceid">
            <label>deviceid</label>
        </input>
        <input ref="/data/phonenumber">
            <label>phonenumber</label>
        </input>
        <input ref="/data/email">
            <label>email</label>
        </input>
        <input ref="/data/username">
            <label>username</label>
        </input>
        <input ref="/data/meta/instanceID">
            <label>instanceID</label>
        </input>
    </h:body>
</h:html>

What's changed

When loading the form, check for bind preloads, and set the value as appropriate.
When preparing for submission, check for end binds and set the value.

@changeset-bot
Copy link

changeset-bot bot commented Nov 27, 2025

🦋 Changeset detected

Latest commit: 9ff6c01

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@getodk/xforms-engine Minor
@getodk/web-forms Minor
@getodk/scenario Minor
@getodk/common Minor
@getodk/xpath Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

const input = container.locator('input');
const input = this.page.locator(
`.question-container:has(.control-text label:text-is("${label}")) input`
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is within the margin of error but in my testing speeds up the suite by around 4%

export interface OdkWebFormsProps {
readonly formXml: string;
readonly fetchFormAttachment: FetchFormAttachment;
readonly preloadProperties?: PreloadProperties;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now optionally pass in properties in to the vue component, specifically the users email, phone number, and username. Additionally you can pass in the deviceid - if you don't then one will be generated for you.

email: 'fake@fake.fake',
phoneNumber: '+1235556789',
username: 'nousername',
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed something for the e2e testing to work with.

return id;
}
const deviceId = DEVICE_ID_PREFIX + crypto.randomUUID();
localStorage.setItem(DEVICE_ID_KEY, deviceId);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default this will get generated and stored in the browser. However it won't get used unless you specify the bind in the xform. I think this is acceptable from a tracking perspective, because the part that goes to the server is opt-in.


return rest;
triggerXformsRevalidateListeners() {
this.listeners.forEach((listener: XformsRevalidateListener) => listener());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using listeners in this way feels slightly awkward. An alternative would be to iterate through the binds looking for revalidate actions which would be cleaner but be a performance hit. I'm open to suggestions here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for jr:preload

2 participants