@gpa-gemstone/react-forms 1.1.46 → 1.1.47
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.d.ts +1 -0
- package/lib/DatePicker.js +16 -10
- package/package.json +1 -1
package/lib/DatePicker.d.ts
CHANGED
package/lib/DatePicker.js
CHANGED
|
@@ -39,19 +39,21 @@ 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;
|
|
42
43
|
// Formats that will be used for dateBoxes
|
|
43
44
|
var boxFormat = "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]HH:mm:ss");
|
|
44
45
|
var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]HH:mm:ss.SSS[Z]");
|
|
45
46
|
var parse = function (r) { return moment(props.Record[props.Field], recordFormat); };
|
|
46
47
|
var divRef = React.useRef(null);
|
|
47
|
-
var
|
|
48
|
-
var
|
|
48
|
+
var _b = React.useState(""), guid = _b[0], setGuid = _b[1];
|
|
49
|
+
var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
|
|
49
50
|
// Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
51
|
+
var _d = React.useState(parse(props.Record).format(boxFormat)), boxRecord = _d[0], setBoxRecord = _d[1];
|
|
52
|
+
var _e = React.useState(parse(props.Record)), pickerRecord = _e[0], setPickerRecord = _e[1];
|
|
53
|
+
var _f = React.useState(false), showOverlay = _f[0], setShowOverlay = _f[1];
|
|
54
|
+
var _g = React.useState(0), top = _g[0], setTop = _g[1];
|
|
55
|
+
var _h = React.useState(0), left = _h[0], setLeft = _h[1];
|
|
56
|
+
var allowEmpty = (_a = props.AllowEmpty) !== null && _a !== void 0 ? _a : false;
|
|
55
57
|
React.useEffect(function () {
|
|
56
58
|
setGuid((0, helper_functions_1.CreateGuid)());
|
|
57
59
|
}, []);
|
|
@@ -60,10 +62,13 @@ function DateTimePicker(props) {
|
|
|
60
62
|
setBoxRecord(parse(props.Record).format(boxFormat));
|
|
61
63
|
}, [props.Record]);
|
|
62
64
|
React.useEffect(function () {
|
|
63
|
-
var _a;
|
|
65
|
+
var _a, _b;
|
|
64
66
|
var valid = moment(boxRecord, boxFormat).isValid();
|
|
67
|
+
if (allowEmpty && boxRecord.length === 0 && !valid && props.Record !== null) {
|
|
68
|
+
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = null, _a)));
|
|
69
|
+
}
|
|
65
70
|
if (valid && parse(props.Record).format(boxFormat) !== boxRecord)
|
|
66
|
-
props.Setter(__assign(__assign({}, props.Record), (
|
|
71
|
+
props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = moment(boxRecord, boxFormat).format(recordFormat), _b)));
|
|
67
72
|
}, [boxRecord]);
|
|
68
73
|
React.useEffect(function () {
|
|
69
74
|
var _a;
|
|
@@ -111,7 +116,8 @@ function DateTimePicker(props) {
|
|
|
111
116
|
(props.Label !== "") ?
|
|
112
117
|
React.createElement("label", null, props.Label == null ? props.Field : props.Label) : null,
|
|
113
118
|
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) {
|
|
114
|
-
|
|
119
|
+
var _a;
|
|
120
|
+
setBoxRecord((_a = evt.target.value) !== null && _a !== void 0 ? _a : "");
|
|
115
121
|
}, onFocus: function () { setShowOverlay(true); }, value: boxRecord, disabled: props.Disabled === undefined ? false : props.Disabled, onClick: function (e) { e.preventDefault(); }, step: "1" }),
|
|
116
122
|
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field.toString() + ' is a required field.' : props.Feedback),
|
|
117
123
|
React.createElement(DateTimePopup_1.default, { Setter: function (d) { setPickerRecord(d); if (props.Type === 'date')
|