From 08bb877dd00fc1223e99c3ef332ad400183f7dd0 Mon Sep 17 00:00:00 2001 From: Julien Ducro Date: Fri, 1 Jun 2018 12:17:55 +0200 Subject: [PATCH] Fix multichoice in TicketForm --- package-lock.json | 3 +-- package.json | 1 + src/Components/TicketField.jsx | 6 ++++++ src/Components/TicketForm.jsx | 7 ++++++- src/style.css | 1 - 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3d5b0000..bf07aa32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7771,8 +7771,7 @@ "immutable": { "version": "3.8.2", "resolved": "https://registry.npmjs.org/immutable/-/immutable-3.8.2.tgz", - "integrity": "sha1-wkOZUUVbs5kT2vKBN28VMOEErfM=", - "dev": true + "integrity": "sha1-wkOZUUVbs5kT2vKBN28VMOEErfM=" }, "import-lazy": { "version": "2.1.0", diff --git a/package.json b/package.json index c84343f8..9542af85 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "@storybook/addon-knobs": "^3.4.3", "classnames": "^2.2.5", "formik": "^0.11.11", + "immutable": "^3.8.2", "moment": "^2.22.1", "moment-hijri": "^2.0.1", "raw-loader": "^0.5.1", diff --git a/src/Components/TicketField.jsx b/src/Components/TicketField.jsx index 33cb434d..285cdafa 100644 --- a/src/Components/TicketField.jsx +++ b/src/Components/TicketField.jsx @@ -7,6 +7,7 @@ import DatePicker from './Inputs/DatePicker'; import DateTimePicker from './Inputs/DateTimePicker'; import Checkboxes from './Choices/Checkboxes'; import DropDown from './Choices/DropDown'; +import MultipleDropDown from './Choices/MultipleDropDown'; import Radio from './Choices/Radio'; class TicketField extends React.Component { @@ -55,6 +56,11 @@ class TicketField extends React.Component { case 'textarea': Component = Textarea; break; + case 'multichoice': + Component = MultipleDropDown; + props.options = field.getIn(['data', 'choices'], []) + .toArray().map(option => ({ value: option.get('id'), label: option.get('title') })); + break; case 'text': default: Component = Text; diff --git a/src/Components/TicketForm.jsx b/src/Components/TicketForm.jsx index 2356ef25..0522dd72 100644 --- a/src/Components/TicketForm.jsx +++ b/src/Components/TicketForm.jsx @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { List } from 'immutable'; import { Formik } from 'formik'; import Yup from 'yup'; import Form from './Form'; @@ -44,7 +45,11 @@ class TicketForm extends React.Component { if (field.get('field_id') === 'department') { initialValues.department = this.state.department; } else { - initialValues[field.get('field_id')] = field.getIn(['data', 'default_value'], ''); + let defaultValue = field.getIn(['data', 'default_value'], ''); + if (defaultValue instanceof List) { + defaultValue = defaultValue.toArray(); + } + initialValues[field.get('field_id')] = defaultValue; } }); return initialValues; diff --git a/src/style.css b/src/style.css index 1478fa20..010a5256 100644 --- a/src/style.css +++ b/src/style.css @@ -530,7 +530,6 @@ & .dp-pc_radios { padding: 23px 10px 11px 0; margin-left: 10px; - height: var(--input-height); width: calc(100% - 20px); } & .dp-pc_radio {