fix (vue-vanilla): preserve strict data types in vue-vanilla enum controls (fixes #2450)#2607
Open
darius-lesch wants to merge 2 commits into
Open
Conversation
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
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue in the
vue-vanillapackage (#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
EnumControlRenderer.vue&EnumOneOfControlRenderer.vue**: Modified theuseVanillaControlparsing callback to extract the selected value directly from thecontrol.value.optionsstate array rather than readingtarget.valuefrom the DOM.target.selectedIndex - 1lookup to accurately map the DOM selection back to the state array, accounting for the hardcoded empty<option>at index0.integerschemas 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'starget.value, which destroyed the original type information. Using the DOM'sselectedIndexas 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.