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
60 stars 10 forks source link

how to skip non selected select option #31

Closed takeAction closed 1 year ago

takeAction commented 1 year ago

I am using FormDataJson.toJson("#searchForm", {skipEmpty: true}), but I found that for select option:

<select name="gender">
    <option value="" selected></option>
    <option value="0" >Male</option>
    <option value="1" >Female</option>
</select>

if there is no valid option selected(that is Male or Female in this case), FormDataJson.toJson("#searchForm", {skipEmpty: true}) still return gender with null, what I suppose is to skip gender. I tried to change <option value="" selected></option> to <option ></option>, still not work.

how can I skip non selected select element?

brainfoolong commented 1 year ago

Thanks for your report. This issue has now been fixed in 2.1.4.

https://github.com/brainfoolong/form-data-json/releases/tag/2.1.4

takeAction commented 1 year ago

Great, thanks, now it works!