Skip to content

Commit b9af4b2

Browse files
committed
Changing description fields to text areas in plant term groups form.
1 parent b3e7ae8 commit b9af4b2

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

src/components/forms/PlantTermGroupsForm/PlantTermGroupsForm.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { lruMemoize } from 'reselect';
77

88
import Icon, { CloseIcon } from '../../icons';
99
import Button, { TheButtonGroup } from '../../widgets/TheButton';
10-
import { TextField } from '../fields';
10+
import { TextField, TextAreaField } from '../fields';
1111

1212
const validate = values => {
1313
const errors = { cs: {}, en: {} };
@@ -79,7 +79,7 @@ const PlantTermGroupsForm = ({ initialValues, onSubmit, onClose }) => {
7979
/>
8080

8181
<Field
82-
component={TextField}
82+
component={TextAreaField}
8383
name="cs.description"
8484
ignoreDirty
8585
maxLength={255}
@@ -112,7 +112,7 @@ const PlantTermGroupsForm = ({ initialValues, onSubmit, onClose }) => {
112112
/>
113113

114114
<Field
115-
component={TextField}
115+
component={TextAreaField}
116116
name="en.description"
117117
ignoreDirty
118118
maxLength={255}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Form, FormControl, FormLabel } from 'react-bootstrap';
4+
import classnames from 'classnames';
5+
6+
import * as styles from './commonStyles.less';
7+
8+
const TextAreaField = ({
9+
input,
10+
meta: { active, dirty, error, warning },
11+
type = 'text',
12+
label = null,
13+
children,
14+
ignoreDirty = false,
15+
className = '',
16+
...props
17+
}) => (
18+
<>
19+
{Boolean(label) && (
20+
<FormLabel className={error ? 'text-danger' : warning ? 'text-warning' : undefined}>{label}</FormLabel>
21+
)}
22+
<FormControl
23+
{...input}
24+
{...props}
25+
as="textarea"
26+
rows={8}
27+
isInvalid={Boolean(error)}
28+
className={
29+
classnames({
30+
'form-control': true,
31+
[styles.dirty]: dirty && !ignoreDirty && !error && !warning,
32+
[styles.active]: active,
33+
'border-danger': error,
34+
'border-warning': !error && warning,
35+
}) +
36+
' ' +
37+
(className || '')
38+
}
39+
/>
40+
{error && <Form.Text className="text-danger"> {error} </Form.Text>}
41+
{!error && warning && <Form.Text className="text-warning"> {warning} </Form.Text>}
42+
{children}
43+
</>
44+
);
45+
46+
TextAreaField.propTypes = {
47+
type: PropTypes.string,
48+
input: PropTypes.shape({
49+
name: PropTypes.string.isRequired,
50+
}).isRequired,
51+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
52+
children: PropTypes.any,
53+
meta: PropTypes.shape({
54+
active: PropTypes.bool,
55+
dirty: PropTypes.bool,
56+
error: PropTypes.any,
57+
warning: PropTypes.any,
58+
}).isRequired,
59+
ignoreDirty: PropTypes.bool,
60+
className: PropTypes.string,
61+
};
62+
63+
export default TextAreaField;

src/components/forms/fields/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { default as NumericTextField } from './NumericTextField.js';
44
export { default as SelectField } from './SelectField.js';
55
export { default as StandaloneRadioField } from './StandaloneRadioField.js';
66
export { default as TextField } from './TextField.js';
7+
export { default as TextAreaField } from './TextAreaField.js';

src/locales/cs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,4 @@
255255
"generic.operationFailed": "Operace selhala",
256256
"generic.reset": "Resetovat",
257257
"generic.save": "Uložit"
258-
}
258+
}

0 commit comments

Comments
 (0)