@gpa-gemstone/react-forms 1.1.48 → 1.1.50

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 CHANGED
@@ -39,39 +39,59 @@ 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 _b = React.useState(""), guid = _b[0], setGuid = _b[1];
49
- var _c = React.useState(false), showHelp = _c[0], setShowHelp = _c[1];
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 _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];
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(""), feedbackMessage = _e[0], setFeedbackMessage = _e[1];
53
54
  var _f = React.useState(false), showOverlay = _f[0], setShowOverlay = _f[1];
54
55
  var _g = React.useState(0), top = _g[0], setTop = _g[1];
55
56
  var _h = React.useState(0), left = _h[0], setLeft = _h[1];
56
- var allowEmpty = (_a = props.AllowEmpty) !== null && _a !== void 0 ? _a : false;
57
57
  React.useEffect(function () {
58
58
  setGuid((0, helper_functions_1.CreateGuid)());
59
59
  }, []);
60
60
  React.useEffect(function () {
61
61
  setPickerRecord(parse(props.Record));
62
62
  setBoxRecord(parse(props.Record).format(boxFormat));
63
+ recordChange.current = false;
63
64
  }, [props.Record]);
64
65
  React.useEffect(function () {
65
66
  var _a, _b;
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)));
67
+ var _c;
68
+ if (!recordChange.current)
69
+ return;
70
+ var date = moment(boxRecord, boxFormat);
71
+ var validStartDate = moment("1753-01-01", "YYYY-MM-DD");
72
+ var valid = true;
73
+ // Invalid date format
74
+ if (!date.isValid()) {
75
+ setFeedbackMessage("Please enter a date as " + boxFormat);
76
+ valid = false;
69
77
  }
78
+ // Date before 1753
79
+ else if (date.isBefore(validStartDate)) {
80
+ setFeedbackMessage("Date cannot be before " + validStartDate.format(boxFormat));
81
+ valid = false;
82
+ }
83
+ else {
84
+ setFeedbackMessage("");
85
+ }
86
+ if (((_c = props.AllowEmpty) !== null && _c !== void 0 ? _c : false) && boxRecord.length === 0 && !valid && props.Record !== null)
87
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = null, _a)));
70
88
  if (valid && parse(props.Record).format(boxFormat) !== boxRecord)
71
89
  props.Setter(__assign(__assign({}, props.Record), (_b = {}, _b[props.Field] = moment(boxRecord, boxFormat).format(recordFormat), _b)));
72
90
  }, [boxRecord]);
73
91
  React.useEffect(function () {
74
92
  var _a;
93
+ if (!recordChange.current)
94
+ return;
75
95
  if (pickerRecord.format(recordFormat) !== parse(props.Record).format(recordFormat))
76
96
  props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = pickerRecord.format(recordFormat), _a)));
77
97
  }, [pickerRecord]);
@@ -130,10 +150,26 @@ function DateTimePicker(props) {
130
150
  return "YYYY-MM-DD";
131
151
  }
132
152
  }
153
+ function getFeedbackMessage() {
154
+ if (feedbackMessage.length != 0) {
155
+ return feedbackMessage;
156
+ }
157
+ else if (props.Feedback == null || props.Feedback.length == 0) {
158
+ return props.Field.toString();
159
+ }
160
+ else {
161
+ return props.Field.toString() + " is a required field.";
162
+ }
163
+ }
133
164
  var showLabel = props.Label !== "";
134
165
  var showHelpIcon = props.Help !== undefined;
135
166
  var label = props.Label === undefined ? props.Field : props.Label;
136
167
  var step = props.Accuracy === 'millisecond' ? '0.001' : (props.Accuracy === 'minute' ? '60' : '1');
168
+ var IsValid = function () {
169
+ if (feedbackMessage.length > 0)
170
+ return false;
171
+ return props.Valid(props.Field);
172
+ };
137
173
  return (React.createElement("div", { className: "form-group", ref: divRef },
138
174
  showHelpIcon || showLabel ?
139
175
  React.createElement("label", null,
@@ -151,12 +187,13 @@ function DateTimePicker(props) {
151
187
  showHelpIcon ?
152
188
  React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
153
189
  : null,
154
- 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) {
190
+ React.createElement("input", { "data-help": guid, className: "gpa-gemstone-datetime form-control " + (IsValid() ? '' : 'is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
155
191
  var _a;
156
192
  setBoxRecord((_a = evt.target.value) !== null && _a !== void 0 ? _a : "");
193
+ recordChange.current = true;
157
194
  }, onFocus: function () { setShowOverlay(true); }, value: boxRecord, disabled: props.Disabled === undefined ? false : props.Disabled, onClick: function (e) { e.preventDefault(); }, step: step }),
158
- 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')
195
+ React.createElement("div", { className: "invalid-feedback" }, getFeedbackMessage()),
196
+ React.createElement(DateTimePopup_1.default, { Setter: function (d) { setPickerRecord(d); recordChange.current = true; if (props.Type === 'date')
160
197
  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
198
  }
162
199
  exports.default = DateTimePicker;
@@ -37,7 +37,7 @@ function Calender(props) {
37
37
  React.useEffect(function () {
38
38
  var d1 = moment([year, month, 1]).startOf('week');
39
39
  var w = [];
40
- while (d1.month() <= month && d1.year() === year) {
40
+ while ((d1.month() <= month && d1.year() === year) || (d1.year() < year)) {
41
41
  w.push({
42
42
  sunday: moment(d1),
43
43
  monday: moment(d1).add(1, 'day'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.48",
3
+ "version": "1.1.50",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",