Skip to content

Commit cb324be

Browse files
committed
fix(forms): fix FormCheckbox and FormSwitch value initialization
1 parent a38eea3 commit cb324be

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

demo/FormExamples.jsx

+31-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import {
1414
export function FormExamples() {
1515
return (
1616
<Form
17-
initialValues={{ textField: 'abc', selectField4: { e: 2, c: 'b' } }}
17+
initialValues={{
18+
textField: 'abc',
19+
autocompleteField1: '2345',
20+
selectField4: { e: 2, c: 'b' },
21+
switchField2: true,
22+
checkboxField2: true,
23+
radioField2: 'b',
24+
}}
1825
onChange={console.info}
1926
onSubmit={(formData, reset) => {
2027
console.log('onSubmit', formData);
@@ -183,6 +190,9 @@ export function FormExamples() {
183190
<div className="col">
184191
<FormGroupSwitch id="switchFieldId" name="switchField" label="Switch field" trueLabel="ON" falseLabel="OFF" />
185192
</div>
193+
<div className="col">
194+
<FormGroupSwitch id="switchFieldId2" name="switchField2" label="Switch field 2" />
195+
</div>
186196
<div className="col">
187197
<FormGroupCheckbox
188198
id="checkboxFieldId"
@@ -191,6 +201,9 @@ export function FormExamples() {
191201
valueLabel="Checkbox description"
192202
/>
193203
</div>
204+
<div className="col">
205+
<FormGroupCheckbox id="checkboxFieldId2" name="checkboxField2" label="Checkbox field 2" />
206+
</div>
194207
<div className="col">
195208
<FormGroupRadio
196209
id="radioFieldId"
@@ -212,6 +225,23 @@ export function FormExamples() {
212225
]}
213226
/>
214227
</div>
228+
<div className="col">
229+
<FormGroupRadio
230+
id="radioFieldId2"
231+
name="radioField2"
232+
label="Radio field 2"
233+
options={[
234+
{
235+
value: 'a',
236+
label: 'A',
237+
},
238+
{
239+
value: 'b',
240+
label: 'B',
241+
},
242+
]}
243+
/>
244+
</div>
215245
</div>
216246

217247
<FormGroupTextarea name="textareaField" label="Textarea field" />

src/forms/FormCheckbox.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function FormCheckbox({ id, name, required, valueLabel }) {
1313
type="checkbox"
1414
className="custom-control-input"
1515
onChange={handleOnChange}
16-
value={getValue()}
16+
checked={getValue()}
1717
ref={registerRef}
1818
/>
1919
<label className="custom-control-label" htmlFor={id}>

src/forms/FormSwitch.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function FormSwitch({ id, name, required, trueLabel, falseLabel }) {
1414
type="checkbox"
1515
className="custom-control-input"
1616
onChange={handleOnChange}
17-
value={value}
17+
checked={value}
1818
ref={registerRef}
1919
/>
2020
<label className="custom-control-label" htmlFor={id}>

0 commit comments

Comments
 (0)