You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I’ve noticed that the json-enc extension currently encodes all input values as strings, even when dealing with <input type="number"> fields. This behavior can lead to incorrect data representation in the resulting JSON when numeric values are expected.
To maintain backward compatibility while providing flexibility, I propose introducing an optional attribute (e.g., data-json-parse-data) that allows users to opt-in to automatic type parsing. When this attribute is present on the <form> element, the extension could:
Convert values from <input type="number"> into actual numbers using Number().
Keep the current behavior (encoding everything as strings) when the attribute is not present.
Hey, first of all you might be interested in the issues bigskysoftware/htmx#1870bigskysoftware/htmx#2401 where many people shared their opinions & some implementation examples on this matter
Long story short ; we won't break backwards compatibility so this can't be a default, therefore your idea (fixing this at the extension level, and making it opt-in) sounds good to me!
Also, depending on your preferences, you may even consider making another entirely separate extension (something like json-enc-typed or whatever) that would, since it'd be a new extension thus not cause any backwards compatibility issue, not even need an extra attribute and enforce types by default.
See the json-enc-custom community extension that is already listed in our community extensions list as an example
Hello,
I’ve noticed that the
json-enc
extension currently encodes all input values as strings, even when dealing with<input type="number">
fields. This behavior can lead to incorrect data representation in the resulting JSON when numeric values are expected.To maintain backward compatibility while providing flexibility, I propose introducing an optional attribute (e.g.,
data-json-parse-data
) that allows users to opt-in to automatic type parsing. When this attribute is present on the<form>
element, the extension could:<input type="number">
into actual numbers usingNumber()
.Example usage:
Expected JSON output with
data-json-parse-data
attribute:Without the attribute, the JSON output would remain:
Would this feature be acceptable as a non-breaking enhancement? If you believe it’s a good idea, I would be happy to submit a PR for it.
Thanks in advance for your feedback!
The text was updated successfully, but these errors were encountered: