get-form-data icon indicating copy to clipboard operation
get-form-data copied to clipboard

Parse numeric fields

Open timwis opened this issue 9 years ago • 5 comments

This pull requests allows <input type="number"> fields to be serialized as numeric values, ex: { "cost": 50 } instead of { "cost": "50" }.

timwis avatar Sep 30 '16 11:09 timwis

looks reasonable to me - tests are failing tho :cry:

yoshuawuyts avatar Sep 30 '16 20:09 yoshuawuyts

It looks like a phantomjs configuration issue. The tests themselves appear to pass. Same thing happened locally.

timwis avatar Sep 30 '16 22:09 timwis

Karma or one of its dependencies had a breaking change in a non-major version, yay! Pinning your own dependencies won't save you; will update build config soon.

What should the expected behaviour be for invalid number inputs if we do this? IIRC they return '' from .value :frowning_face:

insin avatar Oct 03 '16 04:10 insin

Hm, @insin good catch -- a value of "" (empty string) evaluates to NaN, which would be invalid JSON. I would suggest anything that's not a valid number be null. We could do that via parseInt(element.value, 10) || null. Does that speak to what you raised? If not, could you give an example?

timwis avatar Oct 03 '16 09:10 timwis

Hey @insin just checking in on this. What do you think about the above?

timwis avatar Oct 23 '16 15:10 timwis