Using third-party JQuery Modules in custom prompts (select2)


I’m trying to build a custom prompt where enumerators can start typing to find an option. There are pre-packaged options such as select2 (Basic usage | Select2 - The jQuery replacement for select boxes) that would be perfect. But how can I include the code for this in ODK Survey? Any suggestions?

PS: I am aware of this solution: Autocomplete searchable list select one - #12 by chrismclarke, but this has problems when one wants to change an option after having selected one.


As far as I can remember when working on the linked issue, ODK-X uses the tool require.js to manage the import of modules, ensuring that they are imported in the correct order as required and avoid duplicate import across the various pages.

The issue is that the current list of modules made available can’t be modified, as they are included within the ODK-Tables app itself and so would require updating the apk file (technically could be done by taking a fork of the repo, but quite a heavy-handed solution). This is a really sensible approach to ensure the app behaves consistently and avoids each user having to download all the files from a server. So even if locally you put a copy of the jquery-select2 file into the designer/system/libs folder and registered it to load in the system/survey/main.js file, things will work locally but not on a device.

So I think that leaves your only option is to place the required library somewhere that will be uploaded to the server (e.g. app/config/assets and use a custom screen to import using the globally available require. All this starts to become pretty complicated pretty quickly (particularly as this is only for javascript files, and you’d still need to figure out another workaround for the stylesheets), which is why I ended up looking for alternative approaches.

I could be wrong on this though, so interested in knowing if anyone else has other suggestions.