TanStack / form

🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.
https://tanstack.com/form
MIT License
3.74k stars 338 forks source link

Can you submit a value other than true with checkbox #208

Closed unoriginalscreenname closed 6 years ago

unoriginalscreenname commented 6 years ago

Let's say i have an array of items, and i'd like to use a checkbox to push their Id's to the form's values... how would i get the checkbox to add a custom value other than 'true' to the array? This seems like it'd be a common use case.

joepuzzo commented 6 years ago

use the formApis setValue to set a value. You can save an reference of the formApi by using the getApi prop.

joepuzzo commented 6 years ago

@ericmcgregor can i close?

VQH-cmd commented 2 months ago

use the formApis setValue to set a value. You can save an reference of the formApi by using the getApi prop.

How about a simple example base on html code below ?

<input type="checkbox" name="cb[]" value="Item 01" checked />
<input type="checkbox" name="cb[]" value="Item 02" checked />
<input type="checkbox" name="cb[]" value="Item 03" checked />
<input type="checkbox" name="cb[]" value="Item 04" />
<input type="checkbox" name="cb[]" value="Item 05" />
<input type="checkbox" name="cb[]" value="Item 06" />

=> Desire value: ["Item 01", "Item 02", "Item 03"]

and also please add example for multi-checkboxes in docs as well, example react-hook-form has significant clear docs more than this !

Balastrong commented 2 months ago

@VQH-cmd do you want to add a checkbox in the simple example? I'll be happy to review your PR :)