Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 463efd7

Browse files
Port Likert scale item to formik
1 parent 8b494b3 commit 463efd7

File tree

1 file changed

+44
-41
lines changed
  • packages/builder/src/components/ComponentOptions/components/Content/Page/components/ItemOptions/components

1 file changed

+44
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,88 @@
11
import React from 'react'
22

33
import { range } from 'lodash'
4-
import { Control, Field } from 'react-redux-form'
4+
import { Field, FastField, useFormikContext, getIn } from 'formik'
55
import { Row, Col, FormGroup, Label, FormText,
6-
Input, InputGroup, InputGroupAddon, InputGroupText } from 'reactstrap'
6+
InputGroup, InputGroupAddon, InputGroupText } from 'reactstrap'
7+
8+
import { Input } from '../../../../../../../Form'
79

810
import { CodingGroup } from './Coding'
911
import { CollapsingOptions } from './BaseOptions'
1012

11-
export default ({ data, rowIndex }) =>
12-
<>
13+
export default ({ name, index }) => {
14+
const { values } = useFormikContext()
15+
const width = getIn(values, `${ name }.width`)
16+
17+
return <>
1318
<Row form>
1419
<Col>
15-
<Control
16-
model=".label"
20+
<Field
21+
name={ `${ name }.label` }
1722
placeholder="Question"
1823
component={ Input }
19-
debounce={ 300 }
2024
/>
2125
</Col>
2226
</Row>
2327
<CodingGroup
24-
data={ data.items }
25-
model=".items"
26-
itemModel={ `.rows[${ rowIndex }][0]` }
28+
name={ `${ name }.items` }
2729
icon="ellipsis-h-alt"
2830
iconFallbackWeight="s"
2931
/>
3032
<CollapsingOptions
31-
rowIndex={ rowIndex }
33+
name={ name }
34+
index={ index }
3235
shuffle={ true }
3336
>
3437
<Row>
3538
<Col>
3639
<FormGroup className="my-2">
37-
<Label for={ `page-item-${ rowIndex }-width` } className="mb-0">
40+
<Label for={ `page-item-${ index }-width` } className="mb-0">
3841
Scale width
3942
</Label>
4043
<FormText color="muted">
4144
How many points to offer
4245
</FormText>
43-
<Field model=".width" className="mt-1">
44-
<FormGroup>
45-
{
46-
[5, 7, 9, 11].map(w =>
47-
<div
48-
key={ `page-item-${ rowIndex }-width-${ w }` }
49-
className="custom-radio custom-control"
46+
<FormGroup>
47+
{
48+
[5, 7, 9, 11].map(w =>
49+
<div
50+
key={ `page-item-${ index }-width-${ w }` }
51+
className="custom-radio custom-control"
52+
>
53+
<Field
54+
name={ `${ name }.width` }
55+
type="radio"
56+
value={ `${ w }` }
57+
id={ `page-item-${ index }-width-${ w }` }
58+
className="custom-control-input"
59+
/>
60+
<label
61+
htmlFor={ `page-item-${ index }-width-${ w }` }
62+
className="custom-control-label"
5063
>
51-
<input
52-
type="radio" value={ `${ w }` }
53-
id={ `page-item-${ rowIndex }-width-${ w }` }
54-
className="custom-control-input"
55-
/>
56-
<label
57-
htmlFor={ `page-item-${ rowIndex }-width-${ w }` }
58-
className="custom-control-label"
59-
>
60-
{ w }
61-
</label>
62-
</div>
63-
)
64-
}
65-
</FormGroup>
66-
</Field>
64+
{ w }
65+
</label>
66+
</div>
67+
)
68+
}
69+
</FormGroup>
6770
</FormGroup>
6871
</Col>
6972
<Col>
7073
<FormGroup className="my-2">
71-
<Label for={ `page-item-${ rowIndex }-anchors` } className="mb-0">
74+
<Label for={ `page-item-${ index }-anchors` } className="mb-0">
7275
Anchors
7376
</Label>
7477
<FormText color="muted">
7578
Scale anchors
7679
</FormText>
7780
<div className="mt-2">
7881
{
79-
range(data.width).map(i =>
82+
range(width).map(i =>
8083
<Row form
8184
className="my-1"
82-
key={ `page-item-${ rowIndex }-anchors-${ i }` }
85+
key={ `page-item-${ index }-anchors-${ i }` }
8386
>
8487
<Col>
8588
<InputGroup>
@@ -90,10 +93,9 @@ export default ({ data, rowIndex }) =>
9093
</small>
9194
</InputGroupText>
9295
</InputGroupAddon>
93-
<Control
94-
model={ `.anchors[${ i }]` }
96+
<FastField
97+
name={ `${ name }.anchors[${ i }]` }
9598
component={ Input }
96-
debounce={ 300 }
9799
/>
98100
</InputGroup>
99101
</Col>
@@ -106,3 +108,4 @@ export default ({ data, rowIndex }) =>
106108
</Row>
107109
</CollapsingOptions>
108110
</>
111+
}

0 commit comments

Comments
 (0)