enketo-express
enketo-express copied to clipboard
Binary defaults are not loaded for filepicker fields in online-only mode
Describe the bug
When a form provides a binary default for a filepicker field, the jr:
URL is requested rather than the media file it's mapped to in the form's manifest. This behavior is present in both 3.0.3 and 2.7.3. The behavior is not present in offline-capable mode.
To Reproduce
- In an version >=2.8.0, ensure the media is not cached in IndexedDB (e.g. clear in dev tools or use incognito mode).
- Create a form with a binary default for a filepicker input, and map it to a default media file.
- Open the form in online-only mode.
- See an error that the
jr:
URL could not be loaded.
Expected behavior
The form will load the default media file, not the jr:
URL.
Browser and OS (please complete the following information):
- OS: N/A
- Browser: N/A
Additional context
This is probably best solved in enketo-core. Filepicker fields refer to the field's data-loaded-file-name
attribute, which is populated with the jr:
URL. The behavior isn't present, however, for annotation fields, which first refer to the data-loaded-file-name
attribute, then check if it's a jr:
URL and use the media-mapped data-loaded-url
instead. I'm not sure that's the appropriate solution for filepickers.
The behavior is also not present in offline-capable mode, which presents an alternative solution: it ensures data-loaded-file-name
is populated with the mapped URL on load.
This was discovered while working on #356. I'd not caught it before because it was incorrectly falling back to the form cache in IndexedDB. This fallback in online mode was caused by initializing the form cache in order to support last-saved. We should also prevent access to anything other than store.lastSavedRecords
except when in offline-capable mode.