@luomus/laji-form 15.1.14 → 15.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/laji-form.js +1 -1
- package/lib/components/LajiForm.js +1 -1
- package/lib/components/widgets/DateTimeWidget.d.ts +7 -1
- package/lib/components/widgets/DateTimeWidget.js +31 -5
- package/lib/components/widgets/DateWidget.d.ts +6 -0
- package/lib/components/widgets/DateWidget.js +12 -0
- package/package.json +1 -1
|
@@ -479,7 +479,7 @@ class LajiForm extends React.Component {
|
|
|
479
479
|
return state;
|
|
480
480
|
}
|
|
481
481
|
getMemoizedFormContext(props) {
|
|
482
|
-
const nextKey = ["lang", "topOffset", "bottomOffset", "formContext", "settings", "schema", "uiSchemaContext", "lajiGeoServerAddress"].reduce((key, prop) => {
|
|
482
|
+
const nextKey = ["lang", "topOffset", "bottomOffset", "formContext", "settings", "schema", "uiSchemaContext", "mediaMetadata", "lajiGeoServerAddress"].reduce((key, prop) => {
|
|
483
483
|
key[prop] = props[prop];
|
|
484
484
|
return key;
|
|
485
485
|
}, {});
|
|
@@ -10,6 +10,12 @@ export default class DateTimeWidget extends React.Component<any, any, any> {
|
|
|
10
10
|
same: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
11
11
|
path: PropTypes.Requireable<string>;
|
|
12
12
|
}>>;
|
|
13
|
+
plusSixMonths: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
14
|
+
path: PropTypes.Requireable<string>;
|
|
15
|
+
}>>;
|
|
16
|
+
plusSixYear: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
17
|
+
path: PropTypes.Requireable<string>;
|
|
18
|
+
}>>;
|
|
13
19
|
}>>;
|
|
14
20
|
showTimeList: PropTypes.Requireable<boolean>;
|
|
15
21
|
allowOnlyYear: PropTypes.Requireable<boolean>;
|
|
@@ -59,7 +65,7 @@ export default class DateTimeWidget extends React.Component<any, any, any> {
|
|
|
59
65
|
setPlusSixMonths: () => void;
|
|
60
66
|
setPlusYear: () => void;
|
|
61
67
|
formatValue(value: any, options: any, props: any): any;
|
|
62
|
-
|
|
68
|
+
getCurrentDateOrPathDate(path: any): moment.Moment | undefined;
|
|
63
69
|
}
|
|
64
70
|
import * as React from "react";
|
|
65
71
|
import * as moment from "moment";
|
|
@@ -103,10 +103,20 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
this.setPlusSixMonths = () => {
|
|
106
|
-
|
|
106
|
+
const plusSixMonthOptions = utils_1.getUiOptions(this.props).showButtons.plusSixMonths || {};
|
|
107
|
+
const { path } = plusSixMonthOptions;
|
|
108
|
+
const date = this.getCurrentDateOrPathDate(path);
|
|
109
|
+
if (date) {
|
|
110
|
+
this.onChange(date.add(6, "M").format("YYYY-MM-DD"));
|
|
111
|
+
}
|
|
107
112
|
};
|
|
108
113
|
this.setPlusYear = () => {
|
|
109
|
-
|
|
114
|
+
const plusYearOptions = utils_1.getUiOptions(this.props).showButtons.plusYear || {};
|
|
115
|
+
const { path } = plusYearOptions;
|
|
116
|
+
const date = this.getCurrentDateOrPathDate(path);
|
|
117
|
+
if (date) {
|
|
118
|
+
this.onChange(date.add(1, "y").format("YYYY-MM-DD"));
|
|
119
|
+
}
|
|
110
120
|
};
|
|
111
121
|
momentLocalizer(moment);
|
|
112
122
|
}
|
|
@@ -225,12 +235,16 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
|
|
|
225
235
|
const { inputFormat: format } = DateTimeWidget_1.prototype.getStateFromProps(Object.assign(Object.assign({}, props), { date: true, time: true, value }));
|
|
226
236
|
return localizers_1.date.format(value, format, props.formContext.lang);
|
|
227
237
|
}
|
|
228
|
-
|
|
229
|
-
const
|
|
238
|
+
getCurrentDateOrPathDate(path) {
|
|
239
|
+
const formData = this.props.formContext.services.rootInstance.getFormData();
|
|
240
|
+
const value = this.props.value || (path ? utils_1.parseJSONPointer(formData, path, !!"safely") : undefined);
|
|
241
|
+
if (!value) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const date = moment(value);
|
|
230
245
|
if (date.isValid()) {
|
|
231
246
|
return date;
|
|
232
247
|
}
|
|
233
|
-
return moment();
|
|
234
248
|
}
|
|
235
249
|
};
|
|
236
250
|
DateTimeWidget.contextType = ReactContext_1.default;
|
|
@@ -247,6 +261,18 @@ DateTimeWidget.propTypes = {
|
|
|
247
261
|
PropTypes.shape({
|
|
248
262
|
path: PropTypes.string
|
|
249
263
|
})
|
|
264
|
+
]),
|
|
265
|
+
plusSixMonths: PropTypes.oneOfType([
|
|
266
|
+
PropTypes.bool,
|
|
267
|
+
PropTypes.shape({
|
|
268
|
+
path: PropTypes.string
|
|
269
|
+
})
|
|
270
|
+
]),
|
|
271
|
+
plusSixYear: PropTypes.oneOfType([
|
|
272
|
+
PropTypes.bool,
|
|
273
|
+
PropTypes.shape({
|
|
274
|
+
path: PropTypes.string
|
|
275
|
+
})
|
|
250
276
|
])
|
|
251
277
|
})
|
|
252
278
|
]),
|
|
@@ -10,6 +10,12 @@ declare namespace DateWidget {
|
|
|
10
10
|
same: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
11
11
|
path: PropTypes.Requireable<string>;
|
|
12
12
|
}>>;
|
|
13
|
+
plusSixMonths: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
14
|
+
path: PropTypes.Requireable<string>;
|
|
15
|
+
}>>;
|
|
16
|
+
plusSixYear: PropTypes.Requireable<boolean | PropTypes.InferProps<{
|
|
17
|
+
path: PropTypes.Requireable<string>;
|
|
18
|
+
}>>;
|
|
13
19
|
}>>;
|
|
14
20
|
allowOnlyYear: PropTypes.Requireable<boolean>;
|
|
15
21
|
}>>;
|
|
@@ -27,6 +27,18 @@ DateWidget.propTypes = {
|
|
|
27
27
|
PropTypes.shape({
|
|
28
28
|
path: PropTypes.string
|
|
29
29
|
})
|
|
30
|
+
]),
|
|
31
|
+
plusSixMonths: PropTypes.oneOfType([
|
|
32
|
+
PropTypes.bool,
|
|
33
|
+
PropTypes.shape({
|
|
34
|
+
path: PropTypes.string
|
|
35
|
+
})
|
|
36
|
+
]),
|
|
37
|
+
plusSixYear: PropTypes.oneOfType([
|
|
38
|
+
PropTypes.bool,
|
|
39
|
+
PropTypes.shape({
|
|
40
|
+
path: PropTypes.string
|
|
41
|
+
})
|
|
30
42
|
])
|
|
31
43
|
})
|
|
32
44
|
]),
|