@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.
@@ -10,6 +10,7 @@ interface IProps<T> {
10
10
  Format?: string;
11
11
  Type?: ('datetime-local' | 'date');
12
12
  Help?: string | JSX.Element;
13
+ AllowEmpty?: boolean;
13
14
  }
14
15
  export default function DateTimePicker<T>(props: IProps<T>): JSX.Element;
15
16
  export {};
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 _a = React.useState(""), guid = _a[0], setGuid = _a[1];
48
- var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
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 _c = React.useState(parse(props.Record).format(boxFormat)), boxRecord = _c[0], setBoxRecord = _c[1];
51
- var _d = React.useState(parse(props.Record)), pickerRecord = _d[0], setPickerRecord = _d[1];
52
- var _e = React.useState(false), showOverlay = _e[0], setShowOverlay = _e[1];
53
- var _f = React.useState(0), top = _f[0], setTop = _f[1];
54
- var _g = React.useState(0), left = _g[0], setLeft = _g[1];
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), (_a = {}, _a[props.Field] = moment(boxRecord, boxFormat).format(recordFormat), _a)));
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
- setBoxRecord(evt.target.value);
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')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.46",
3
+ "version": "1.1.47",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",