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

IncludeButtonValues does not include button values #18

Closed KES777 closed 2 years ago

KES777 commented 2 years ago

To Reproduce 1.FormDataJson.toJson( form, { includeButtonValues: true } )

brainfoolong commented 2 years ago

Thanks for test, do you have an example form?

The normal tests pass successfull for this option -> https://raw.githack.com/brainfoolong/form-data-json/v2-dev/docs/tests/test.html

KES777 commented 2 years ago

image

<form id='ajax-form' action="/" method="GET" class="js-ajax">
  <input name='test'>
  <button type='submit' class="btn btn-primary">Test form</button>
  <input  type='submit' class="btn btn-primary" value="Test form"/>
</form>
<input type='submit' class="btn btn-primary" form='regular-form' value="Outer button">
<a     type='submit' class="btn btn-primary" form='regular-form'
  href="#" role="button"
>Outer link as button</a>

and full page index.html.zip

brainfoolong commented 2 years ago

Your form is not correct in this case. Both <button type='submit' and <input type='submit' missing a "name" attribute. <button> Also miss a value attribute.

This is standard behaviour, each form element that need to submit a value, must have a name, otherwise nothing is submited (Because of undefined name).

The <button> need also a value attribute, which than get's submited (And also picked up by this library)

KES777 commented 2 years ago

You are right, I miss the names for my buttons