@gpa-gemstone/react-forms 1.1.48 → 1.1.49
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/lib/DatePicker.js +17 -12
- package/package.json +1 -1
package/lib/DatePicker.js
CHANGED
|
@@ -39,39 +39,43 @@ var DateTimePopup_1 = require("./DateTimeUI/DateTimePopup");
|
|
|
39
39
|
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
40
40
|
var HelperMessage_1 = require("./HelperMessage");
|
|
41
41
|
function DateTimePicker(props) {
|
|
42
|
-
var _a;
|
|
43
42
|
// Formats that will be used for dateBoxes
|
|
44
43
|
var boxFormat = getBoxFormat(props.Type, props.Accuracy);
|
|
45
44
|
var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]HH:mm:ss.SSS[Z]");
|
|
46
45
|
var parse = function (r) { return moment(props.Record[props.Field], recordFormat); };
|
|
47
46
|
var divRef = React.useRef(null);
|
|
48
|
-
var
|
|
49
|
-
var
|
|
47
|
+
var recordChange = React.useRef(false);
|
|
48
|
+
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
49
|
+
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
50
50
|
// Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var allowEmpty = (_a = props.AllowEmpty) !== null && _a !== void 0 ? _a : false;
|
|
51
|
+
var _c = React.useState(parse(props.Record).format(boxFormat)), boxRecord = _c[0], setBoxRecord = _c[1];
|
|
52
|
+
var _d = React.useState(parse(props.Record)), pickerRecord = _d[0], setPickerRecord = _d[1];
|
|
53
|
+
var _e = React.useState(false), showOverlay = _e[0], setShowOverlay = _e[1];
|
|
54
|
+
var _f = React.useState(0), top = _f[0], setTop = _f[1];
|
|
55
|
+
var _g = React.useState(0), left = _g[0], setLeft = _g[1];
|
|
57
56
|
React.useEffect(function () {
|
|
58
57
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
59
58
|
}, []);
|
|
60
59
|
React.useEffect(function () {
|
|
61
60
|
setPickerRecord(parse(props.Record));
|
|
62
61
|
setBoxRecord(parse(props.Record).format(boxFormat));
|
|
62
|
+
recordChange.current = false;
|
|
63
63
|
}, [props.Record]);
|
|
64
64
|
React.useEffect(function () {
|
|
65
65
|
var _a, _b;
|
|
66
|
+
var _c;
|
|
67
|
+
if (!recordChange.current)
|
|
68
|
+
return;
|
|
66
69
|
var valid = moment(boxRecord, boxFormat).isValid();
|
|
67
|
-
if (
|
|
70
|
+
if (((_c = props.AllowEmpty) !== null && _c !== void 0 ? _c : false) && boxRecord.length === 0 && !valid && props.Record !== null)
|
|
68
71
|
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = null, _a)));
|
|
69
|
-
}
|
|
70
72
|
if (valid && parse(props.Record).format(boxFormat) !== boxRecord)
|
|
71
73
|
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = moment(boxRecord, boxFormat).format(recordFormat), _b)));
|
|
72
74
|
}, [boxRecord]);
|
|
73
75
|
React.useEffect(function () {
|
|
74
76
|
var _a;
|
|
77
|
+
if (!recordChange.current)
|
|
78
|
+
return;
|
|
75
79
|
if (pickerRecord.format(recordFormat) !== parse(props.Record).format(recordFormat))
|
|
76
80
|
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = pickerRecord.format(recordFormat), _a)));
|
|
77
81
|
}, [pickerRecord]);
|
|
@@ -154,9 +158,10 @@ function DateTimePicker(props) {
|
|
|
154
158
|
React.createElement("input", { "data-help": guid, className: "gpa-gemstone-datetime form-control" + (props.Valid(props.Field) ? '' : ' is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
|
|
155
159
|
var _a;
|
|
156
160
|
setBoxRecord((_a = evt.target.value) !== null && _a !== void 0 ? _a : "");
|
|
161
|
+
recordChange.current = true;
|
|
157
162
|
}, onFocus: function () { setShowOverlay(true); }, value: boxRecord, disabled: props.Disabled === undefined ? false : props.Disabled, onClick: function (e) { e.preventDefault(); }, step: step }),
|
|
158
163
|
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field.toString() + ' is a required field.' : props.Feedback),
|
|
159
|
-
React.createElement(DateTimePopup_1.default, { Setter: function (d) { setPickerRecord(d); if (props.Type === 'date')
|
|
164
|
+
React.createElement(DateTimePopup_1.default, { Setter: function (d) { setPickerRecord(d); recordChange.current = true; if (props.Type === 'date')
|
|
160
165
|
setShowOverlay(false); }, Show: showOverlay, DateTime: pickerRecord, Valid: props.Valid(props.Field), Top: top, Center: left, Type: props.Type === undefined ? 'date' : props.Type, Accuracy: props.Accuracy })));
|
|
161
166
|
}
|
|
162
167
|
exports.default = DateTimePicker;
|