brainfoolong / form-data-json

A zero dependency, cross browser library to easily get or set/manipulate form input values as/from a json object.
https://brainfoolong.github.io/form-data-json
MIT License
57 stars 10 forks source link

Proposal to Improve the Manipulation of Masked Field Values in Forms #37

Closed kurybr closed 3 months ago

kurybr commented 4 months ago

It would be good to have a way to manipulate the value of the field, for example, fields that use masks (like currency) are bringing the complete string "USD$ 100.32".

Just as we have the filterInput function, there could be something that iterates between the fields and allows us to manipulate the field's return; it would give much more flexibility to the developer.

This way, I could take the field that has the mask and process the value to return it as a number "100.32".

kurybr commented 4 months ago

I create a suggestion

https://github.com/brainfoolong/form-data-json/pull/38

brainfoolong commented 4 months ago

Hey. Thanks for the suggestion. Unfortunately, manipulating returned form data on the fly is not in scope for this library. It adds more complexity for a very niche feature. Futhermore, it will make the library be able to return data that is incompatible with fromJson or even can return data that is not JSON compatible anymore (By returning a function or other data type for example).

The main idea here was to keep the library as simple as possible.

Even the inputFilter was a little mistake to integrate, but this is a legacy feature and cannot be removed.