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

Add description that the library requires <input> has 'name' attribute #40

Closed KES777 closed 2 months ago

KES777 commented 2 months ago

If elements does not have name, then its value is skipped. It would be nice to have this documented.

Even better a new configuration options could be provided which controls this. Eg. 'includeUnnamed = "custom_key_store_unnamed_inputs"'. If this options is set, then all unnamed inputs could be stored under "custom_key_store_unnamed_inputs" key as array.

includeUnnamed="no_name_inputs";

{
  no_name_inputs : [
    "value for the first input",
    "value for the second input",
  ]
}

Though it could conflict with "skipEmpty". If it is true, then it will not be possible to understand if the value "first input" come from first element or second (when first is empty). Or "skipEmpty" could be ignored for unnamed inputs and always return in values for all elements.

brainfoolong commented 2 months ago

Thanks for the feedback. I don't think that this make any sense.

It is intuitiv enough that when an element have no name that it cannot be in the output, because the name is the key. This is also default behaviour from any other existing library or even the native FormData.

This don't need to be documented because it simple is self-explanatory that a missing "name" attribute result in skipped in the output. Even if it is not clear at first glance because someone is new to forms, you see it when you first use the function.