@citizensadvice/form-to-rack-params
v1.2.0
Published
Convert form parameters to an object using the same logic as Rack
Downloads
4,935
Keywords
Readme
formToRackParams(form: HTMLFormElement | FormData): Object
Converts a <Form>
's parameters to an object using the same logic as Rack.
This is mainly intended for testing JavaScript components that generate HTML forms to be submitted to Rails.
<form>
<input type="hidden" name="foo[bar][][id]" value="1" />
<input type="hidden" name="foo[bar][][id]" value="2" />
</form>
import formToRackParams from '@citizensadvice/form-to-rack-params';
const form = document.querySelector('form');
formToRakeParams(form);
/* =>
foo: {
bar: [
{ id: '1' },
{ id: '2' },
],
}
*/