-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 [#4908] Add Service and FormVariablesSelect fields
- Loading branch information
1 parent
4024bf6
commit 5d89888
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...penforms/js/components/admin/form_design/registrations/json/fields/FormVariablesSelect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {useField} from 'formik'; | ||
import PropTypes from 'prop-types'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import Field from 'components/admin/forms/Field'; | ||
import FormRow from 'components/admin/forms/FormRow'; | ||
import ReactSelect from 'components/admin/forms/ReactSelect'; | ||
|
||
const FormVariablesSelect = ({options}) => { | ||
const [fieldProps, , fieldHelpers] = useField('formVariables'); | ||
const {setValue} = fieldHelpers; | ||
|
||
// TODO-4098: what does this do? | ||
const values = []; | ||
if (fieldProps.value && fieldProps.value.length) { | ||
fieldProps.value.forEach(item => { | ||
const selectedOption = options.find(option => option.value === item); | ||
if (selectedOption) { | ||
values.push(selectedOption); | ||
} | ||
}); | ||
} | ||
|
||
return ( | ||
<FormRow> | ||
<Field | ||
name="formVariables" | ||
label={ | ||
<FormattedMessage | ||
description="JSON registration options 'formVariables' label" | ||
defaultMessage="Form variables" | ||
/> | ||
} | ||
> | ||
<ReactSelect | ||
name="formVariables" | ||
options={options} | ||
isMulti | ||
required | ||
value={values} | ||
// TODO-4098: what does this do? | ||
onChange={newValue => { | ||
setValue(newValue.map(item => item.value)); | ||
}} | ||
/> | ||
</Field> | ||
</FormRow> | ||
); | ||
}; | ||
|
||
FormVariablesSelect.propTypes = { | ||
options: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
value: PropTypes.string.isRequired, | ||
label: PropTypes.node.isRequired, | ||
}) | ||
).isRequired, | ||
}; | ||
|
||
export default FormVariablesSelect; |
5 changes: 5 additions & 0 deletions
5
src/openforms/js/components/admin/form_design/registrations/json/fields/Service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Service = () => { | ||
return "asdf" | ||
} | ||
|
||
export default Service |