Skip to content

Commit 936e489

Browse files
committed
Added date-picker.js
Also fixed the validation issue such the (*) appears in the checkboxes and datepickers. However, it isn't on the single checkbox.
1 parent fbbfe14 commit 936e489

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

packages/ant-component-mapper/src/common/multiple-choice-list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ const Wrapper = ({ label, isRequired, children, meta, validateOnMount, helperTex
2323
<Form required={isRequired} layout="vertical" component="fieldset">
2424
<Form.Item
2525
label={label}
26+
name={label}
2627
help={helperText || description || invalid}
2728
validateStatus={!invalid ? '' : 'error'}
2829
rules={[
2930
{
3031
required: isRequired,
3132
message: 'Required'
3233
}
33-
]} //this is useless
34+
]}
3435
>
3536
{children}
3637
</Form.Item>

packages/ant-component-mapper/src/files/component-mapper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PlainText from './plain-text';
55
import TextField from './text-field';
66
import TextArea from './text-area';
77
import Checkbox from './checkbox';
8+
import DatePicker from './date-picker'
89

910
export const components = {};
1011

@@ -16,7 +17,7 @@ const componentMapper = {
1617
[componentTypes.SUB_FORM]: () => <div>sub form</div>,
1718
[componentTypes.RADIO]: () => <div>Radio field</div>,
1819
[componentTypes.TABS]: Tabs,
19-
[componentTypes.DATE_PICKER]: () => <div>Date picker</div>,
20+
[componentTypes.DATE_PICKER]: DatePicker,
2021
[componentTypes.TIME_PICKER]: () => <div>Time picker</div>,
2122
[componentTypes.SELECT]: () => <div>Select field</div>,
2223
[componentTypes.PLAIN_TEXT]: PlainText,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { DatePicker as AntDatePicker, Form } from 'antd';
4+
import { validationError } from '../common/helpers';
5+
import { meta, input } from '@data-driven-forms/common/src/prop-types-templates';
6+
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
7+
8+
const DatePicker = (props) => {
9+
const { input, isReadOnly, isDisabled, placeholder, isRequired, label, helperText, description, validateOnMount, meta } = useFieldApi(props);
10+
const invalid = validationError(meta, validateOnMount);
11+
const placeholderDisplay = placeholder ? placeholder : 'Select date';
12+
return (
13+
<Form layout="vertical">
14+
<Form.Item
15+
label={label}
16+
rules={[
17+
{
18+
required: isRequired,
19+
message: 'Required'
20+
}
21+
]}
22+
name={label}
23+
validateStatus={!invalid ? '' : 'error'}
24+
help={invalid || helperText || description}
25+
>
26+
<AntDatePicker
27+
disabled={isDisabled || isReadOnly}
28+
placeholder={placeholderDisplay}
29+
required={isRequired}
30+
error={!!invalid}
31+
readOnly={isReadOnly}
32+
{...input}
33+
value={input.value || null}
34+
/>
35+
</Form.Item>
36+
</Form>
37+
);
38+
};
39+
40+
DatePicker.propTypes = {
41+
input,
42+
meta,
43+
isReadOnly: PropTypes.bool,
44+
isDisabled: PropTypes.bool,
45+
placeholder: PropTypes.node,
46+
isRequired: PropTypes.bool,
47+
label: PropTypes.node,
48+
helperText: PropTypes.node,
49+
validateOnMount: PropTypes.bool,
50+
locale: PropTypes.string,
51+
description: PropTypes.node
52+
};
53+
54+
export default DatePicker;

0 commit comments

Comments
 (0)