Skip to content

fix (vue-vanilla): preserve strict data types in vue-vanilla enum controls (fixes #2450)#2607

Open
darius-lesch wants to merge 2 commits into
eclipsesource:masterfrom
darius-lesch:fix/enum-coercion-for-vue-vanilla
Open

fix (vue-vanilla): preserve strict data types in vue-vanilla enum controls (fixes #2450)#2607
darius-lesch wants to merge 2 commits into
eclipsesource:masterfrom
darius-lesch:fix/enum-coercion-for-vue-vanilla

Conversation

@darius-lesch

@darius-lesch darius-lesch commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Description
This PR fixes an issue in the vue-vanilla package (#2450) where selecting a non-string value (like an integer) from an enum dropdown implicitly coerces the value to a string in the JSONForms state, causing schema validation failures.

Main Changes

  • **Updated EnumControlRenderer.vue & EnumOneOfControlRenderer.vue**: Modified the useVanillaControl parsing callback to extract the selected value directly from the control.value.options state array rather than reading target.value from the DOM.
  • Index Mapping: Applied a target.selectedIndex - 1 lookup to accurately map the DOM selection back to the state array, accounting for the hardcoded empty <option> at index 0.
  • Test Coverage: Added new unit tests for both renderers using integer schemas to explicitly verify that strict number types are preserved in the data state.

Motivation & Justification
Native HTML <select> elements inherently serialize all bound data into strings. The previous implementation relied on reading the DOM's target.value, which destroyed the original type information. Using the DOM's selectedIndex as a pointer to fetch the original value from the JSONForms state array bypasses this serialization completely. This provides a robust, universally type-safe solution for all schema types (numbers, booleans, etc.) without relying on brittle manual type-casting logic.

This commit fixes an issue where selecting an integer value in the `EnumControlRenderer` or `EnumOneOfControlRenderer` would incorrectly write a stringified version of the integer to the JSONForms data state, causing validation errors.

The components were updated to look up the correct value from `options` using `selectedIndex - 1` (accounting for the hardcoded empty option at index 0) instead of relying on `target.value`.

Additional tests were added to explicitly verify this behavior with an `integer` based schema.
…-4822673399870400796

fix(vue-vanilla): fix type coercion for Enum and OneOfEnum controls
@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for jsonforms-examples ready!

Name Link
🔨 Latest commit d73dbd2
🔍 Latest deploy log https://app.netlify.com/projects/jsonforms-examples/deploys/6a632fa565f09c0008f8c6ac
😎 Deploy Preview https://deploy-preview-2607--jsonforms-examples.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@darius-lesch darius-lesch changed the title fix (vue-vanilla): preserve strict data types in vue-vanilla enum controls (fixes #2540) fix (vue-vanilla): preserve strict data types in vue-vanilla enum controls (fixes #2450) Jul 24, 2026
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.

1 participant