Skip to content

feat(custom-forms): legacy custom forms plugin (#480)#485

Draft
kabaros wants to merge 36 commits intomasterfrom
alpha
Draft

feat(custom-forms): legacy custom forms plugin (#480)#485
kabaros wants to merge 36 commits intomasterfrom
alpha

Conversation

@kabaros
Copy link
Contributor

@kabaros kabaros commented Sep 11, 2025

implements https://dhis2.atlassian.net/browse/DHIS2-19900

This plugin adds support for legacy custom forms in the new data-entry app. It aims to make using these custom forms (with JavaScript code) as frictionless as possible so that the old forms can - ideally - work as they are without changes. The approach for this support is achieved by:

  1. Providing all the JavaScript base libraries that were available in the Struts app pre-v42, i.e. jQuery, jQuery UI etc..
  2. Updating the global scripts in form.js to work for v42+ maintaining - as much as possible - their existing interface so that the upgrade is seamless for existing consumers.
  3. Providing a shim for other implicit contracts, i.e. HTML elements like #selectedDataSet or #selectedPeriodId that were used in the past for certain operations like getting current dataSet or period.
  4. Document workarounds for operations that can not be supported as they are so that implementers and developers have a way forward with the least amount of hassle possible.

ToDos

  • The core: load all JS files defined in the old Struts app, and a shim for commonly used global properties and functions
  • support dhis2.de.currentOrganisationUnitId and other properties available in dhis2.de
  • Forms with an attribute option combo don't work currently
  • update all the form.js API calls that are deprecated (i.e. all the calls to .action struts routes)
  • completing/incompleting forms
  • validating forms
  • view details of data elements
  • view history of data elements
  • open details with Cmd/Ctrl - Enter
  • printing forms - won't do - it's not possible given there is total flexibility in CSS in custom forms. The authors can provide print CSS if they wish
  • offline support
  • support all/most field types (date, etc...)
    • support Date value type
    • support File value type
  • forms with option sets
  • forms with indicators
  • show error messages with useAlert (proxy setHeaderDelayMessage to useAlert)
  • support inline CSS
  • API requests to relative path: '../api/data....' (handled with jQuery AJAX override)
  • Support custom tabs: a lot of custom tabs with jquery plugins: $( "#tabs" ).tabs();
  • jquery UI: floatThead, tabs,
  • pass "localize string" from the parent app (and other localization functions)
  • Others
    • values outside of min/max range for a given DE are accepted in custom form implementation, but would be warned in non-custom forms [maybe this is consistent with old app, or we don’t care]
    • sometimes the plugin height is less than the total available, so it makes a kind of weird scrollbar. I guess this is just a css issue that we don’t care about for now:
  • decide what to bring over from the old Struts /src/main/webapp/dhis-web-commons/javascripts/commons.js
    • show/hide loader - an idea was to use the loader from the new data-entry app, but this is technically difficult as it causes a re-render of the form. Likely we will just support whatever loader the custom form had in the code (i.e. jQuery UI)
    • ensure events: dhis2.util.on(dhis2.de.event.formReady", dhis2.de.event.dataValuesLoaded, dhis2.de.event.dataValueSaved, dhis2.de.event.completed
    • which base styles?
  • Possible future optimisations:
    • concatenate all JS for faster loading
    • Remove the calendar/period helpers and logic
    • maybe make loading some JS files optional (through dataStore seting?)
    • ? Replace jQuery DOM manipulation with native APIs as they're mostly redundant in modern browsers now
    • ensure the external scripts are cached on production (or reused by the plugin) etc... the service worker is taking care of that

Testing

To test the custom form plugin, run Aggregate the Data Entry app from this branch as usual (yarn install && yarn start), then navigate to any existing custom form.

This PR supersedes this PoC: #346

Current state (5/09)

custom-form-2025-09-05.webm

supersedes #480

* feat: support custom forms with plugins

* chore: add placeholder custom-form plugin to project

* add javascript files from core

* use javascript files from core

* chore: update external JS files

* chore: original SA custom form

* chore: improve the shim for the plguin (getting SA covid to work)

* refactor: clean comments and lint issues

* chore: support internal form CSS and proxy setHeaderDelayMessage to useAlert

* refactor: rename folder name

* refactor: organise files and cleanup comments

* refactor: move external files to a common folder

* fix: update scripts paths so that they work in production build

* fix: omit plugin and plugin.js from pre-cache so that it works in production build

* fix: ignore linting legacy jQuery/struts files

to make it easier to compare with originals

* test: fix failing tests
@kabaros kabaros changed the title feat(custom-forms): legacy custom forms plugin base (#480) feat(custom-forms): legacy custom forms plugin (#480) Sep 11, 2025
@dhis2-bot
Copy link
Contributor

dhis2-bot commented Sep 11, 2025

🚀 Deployed on https://pr-485--dhis2-data-entry.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify September 11, 2025 16:22 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 11, 2025 17:08 Inactive
dhis2-bot and others added 19 commits September 11, 2025 17:18
# [101.1.0-alpha.1](v101.0.20...v101.1.0-alpha.1) (2025-09-11)

### Bug Fixes

* revert d2.config to publish to alpha ([f45b98f](f45b98f))

### Features

* **custom-forms:** legacy custom forms plugin base ([#480](#480)) ([f88867a](f88867a))
# [101.1.0-alpha.2](v101.1.0-alpha.1...v101.1.0-alpha.2) (2025-09-11)

### Bug Fixes

* alpha release to apphub ([28c3fc1](28c3fc1))
# [101.1.0-alpha.3](v101.1.0-alpha.2...v101.1.0-alpha.3) (2025-09-11)

### Bug Fixes

* fix publishing on pre-release branches ([17caaac](17caaac))
# [101.1.0-alpha.4](v101.1.0-alpha.3...v101.1.0-alpha.4) (2025-09-30)

### Features

* add support for attribute option combos ([fb7a1cb](fb7a1cb))
# [101.1.0-alpha.5](v101.1.0-alpha.4...v101.1.0-alpha.5) (2025-10-09)

### Features

* support viewing data item details ([97b11b3](97b11b3))
fix: update indicators to include denominators
# [101.1.0-alpha.6](v101.1.0-alpha.5...v101.1.0-alpha.6) (2025-10-15)

### Features

* add support for option sets ([008c368](008c368))
* add support indicators ([8767049](8767049))
* feat(custom-forms): support offline mode

* fix: prevent re-renders and highlight all synced fields once online

fix(offline): highlight all synced fields when online

fix(offline): prevent extra re-renders for plugin
# [101.1.0-alpha.7](v101.1.0-alpha.6...v101.1.0-alpha.7) (2025-11-12)

### Features

* **custom-forms:** support offline mode ([#495](#495)) ([4ed158f](4ed158f))
kabaros and others added 2 commits November 26, 2025 19:19
# [101.1.0-alpha.8](v101.1.0-alpha.7...v101.1.0-alpha.8) (2025-11-26)

### Bug Fixes

* pass legacy localised strings to plugin ([61f9984](61f9984))
* re-add dhis2.validation.js  as it is still used in some helpers ([cce316b](cce316b))
* use native datepicker for DATE fields ([7d02d54](7d02d54))

### Features

* open details bar using cmd+enter ([72d055d](72d055d))
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
526 New issues
105 New Critical Issues (required ≤ 0)
520 New Code Smells (required ≤ 0)
6 New Bugs (required ≤ 0)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

dhis2-bot and others added 12 commits January 14, 2026 12:02
# [101.1.0-alpha.9](v101.1.0-alpha.8...v101.1.0-alpha.9) (2026-01-14)

### Bug Fixes

* support min/max values validation ([34beffa](34beffa))
# [101.1.0-alpha.10](v101.1.0-alpha.9...v101.1.0-alpha.10) (2026-01-14)

### Bug Fixes

* change alert shim to allow passing AlerBar options ([9e0a7ae](9e0a7ae))

### Features

* support files value types ([3d95a3e](3d95a3e))
# [101.1.0-alpha.11](v101.1.0-alpha.10...v101.1.0-alpha.11) (2026-01-26)

### Bug Fixes

* rerun pipeline ([17ebe47](17ebe47))
* **DHIS2-20563:** use dataset ID instead of form ID to get the custom form ([a0c8ee7](a0c8ee7))
* **DHIS2-20563:** validate valueTypes on the client-side ([a37c5ec](a37c5ec))
* **DHIS2-20575:** show loader until form is ready to interact with ([8dca817](8dca817))
* fix(DHIS2-20567): show modern styles for html-only forms

* refactor: add comment for htmlCode query

Co-authored-by: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com>

---------

Co-authored-by: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com>
# [101.1.0-alpha.12](v101.1.0-alpha.11...v101.1.0-alpha.12) (2026-02-04)

### Bug Fixes

* **DHIS2-20567:** show modern styles for html-only forms ([#509](#509)) ([3b5e95a](3b5e95a))
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
8 New issues
1 New Critical Issues (required ≤ 0)
8 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

2 participants