Skip to content

Commit

Permalink
Fix multichoice in TicketForm
Browse files Browse the repository at this point in the history
  • Loading branch information
jducro committed Jun 1, 2018
1 parent ae6c85a commit 08bb877
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/Components/TicketField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/Components/TicketForm.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 08bb877

Please sign in to comment.