Skip to content

Commit

Permalink
[#40] Fix translation for multiple option
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Apr 28, 2022
1 parent 6165e1a commit 76cabee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/src/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"order": 5,
"type": "cascade",
"api": {
"endpoint": "https://tech-consultancy.akvo.org/akvo-flow-web-api/cascade/seap/cascade-296940912-v1.sqlite/",
"endpoint": "https://tech-consultancy.akvo.org/akvo-flow-web-api/cascade/seap/cascade-296940912-v1.sqlite",
"initial": 0,
"list": false
},
Expand Down
12 changes: 9 additions & 3 deletions src/fields/TypeMultipleOption.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { Divider, Form, Select, Input, Button } from 'antd'
import { PlusOutlined } from '@ant-design/icons'
import { Extra } from '../support'
Expand All @@ -15,10 +15,11 @@ const TypeMultipleOption = ({
allowOtherText,
extra
}) => {
const [options, setOptions] = useState(option)
const [options, setOptions] = useState([])
const [newOption, setNewOption] = useState('')
const [extraOption, setExtraOption] = useState([])
const addNewOption = (e) => {
setOptions([...options, { name: newOption, label: newOption }])
setExtraOption([...extraOption, { name: newOption, label: newOption }])
e.preventDefault()
setNewOption('')
}
Expand All @@ -29,6 +30,11 @@ const TypeMultipleOption = ({
? extra.filter((ex) => ex.placement === 'before')
: []
const extraAfter = extra ? extra.filter((ex) => ex.placement === 'after') : []

useEffect(() => {
setOptions([...option, ...extraOption])
}, [option, extraOption])

return (
<Form.Item
className='arf-field'
Expand Down

0 comments on commit 76cabee

Please sign in to comment.