react-form-builder-more-flexibility 1.0.23 → 1.0.25
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/app.js +1 -1
- package/lib/form-elements/date-picker.js +88 -39
- package/package.json +1 -1
|
@@ -47,32 +47,46 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
47
47
|
(0, _classCallCheck2["default"])(this, DatePicker);
|
|
48
48
|
_this = _super.call(this, props);
|
|
49
49
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleChange", function (dt) {
|
|
50
|
-
var placeholder;
|
|
51
50
|
var formatMask = _this.state.formatMask;
|
|
52
51
|
var iOSFormatMask = 'yyyy-MM-dd';
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
|
|
53
|
+
// Helper function to check if a date is valid
|
|
54
|
+
var isValidDate = function isValidDate(d) {
|
|
55
|
+
return d instanceof Date && !Number.isNaN(d.getTime());
|
|
56
|
+
};
|
|
57
|
+
var formattedDate = '';
|
|
58
|
+
var internalValue = null;
|
|
59
|
+
var placeholder = '';
|
|
60
|
+
|
|
61
|
+
// Handle dt.value instance of Date
|
|
62
|
+
if (dt && dt.value instanceof Date && isValidDate(dt.value)) {
|
|
63
|
+
formattedDate = (0, _dateFns.format)(dt.value, iOSFormatMask);
|
|
64
|
+
internalValue = dt.value;
|
|
65
|
+
placeholder = formatMask.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
// Handle dt.target
|
|
68
|
+
else if (dt && dt.target) {
|
|
69
|
+
placeholder = dt.target.value === '' ? formatMask.toLowerCase() : '';
|
|
55
70
|
var dateValue = dt.target.value ? parseDate(dt.target.value, formatMask) : null;
|
|
56
|
-
if (
|
|
57
|
-
|
|
71
|
+
if (isValidDate(dateValue)) {
|
|
72
|
+
formattedDate = (0, _dateFns.format)(dateValue, iOSFormatMask);
|
|
73
|
+
internalValue = dateValue;
|
|
58
74
|
} else {
|
|
59
|
-
|
|
60
|
-
_this.setState({
|
|
61
|
-
value: formattedDate,
|
|
62
|
-
internalValue: dateValue,
|
|
63
|
-
placeholder: placeholder
|
|
64
|
-
});
|
|
75
|
+
console.log('Invalid date:', dt.target.value);
|
|
65
76
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
77
|
+
}
|
|
78
|
+
// Handle general dt scenario
|
|
79
|
+
else if (dt && isValidDate(dt)) {
|
|
80
|
+
formattedDate = (0, _dateFns.format)(dt, iOSFormatMask);
|
|
81
|
+
internalValue = dt;
|
|
68
82
|
} else {
|
|
69
|
-
|
|
70
|
-
_this.setState({
|
|
71
|
-
value: _formattedDate,
|
|
72
|
-
internalValue: dt,
|
|
73
|
-
placeholder: placeholder
|
|
74
|
-
});
|
|
83
|
+
console.log('Invalid date:', dt);
|
|
75
84
|
}
|
|
85
|
+
_this.setState({
|
|
86
|
+
value: formattedDate,
|
|
87
|
+
internalValue: internalValue,
|
|
88
|
+
placeholder: placeholder
|
|
89
|
+
});
|
|
76
90
|
});
|
|
77
91
|
_this.inputField = /*#__PURE__*/_react["default"].createRef();
|
|
78
92
|
var _DatePicker$updateFor = DatePicker.updateFormat(props, null),
|
|
@@ -101,21 +115,59 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
101
115
|
}, {
|
|
102
116
|
key: "handleDateChange",
|
|
103
117
|
value: function handleDateChange(event) {
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
var _this$state = this.state,
|
|
119
|
+
month = _this$state.month,
|
|
120
|
+
day = _this$state.day,
|
|
121
|
+
year = _this$state.year;
|
|
122
|
+
var newValue = event.target.value;
|
|
123
|
+
switch (event.target.name) {
|
|
124
|
+
case 'month':
|
|
125
|
+
if (newValue > 12) {
|
|
126
|
+
this.setState({
|
|
127
|
+
month: '12'
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
this.setState({
|
|
131
|
+
month: newValue
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case 'day':
|
|
136
|
+
if (newValue > 31) {
|
|
137
|
+
this.setState({
|
|
138
|
+
day: '31'
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
this.setState({
|
|
142
|
+
day: newValue
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case 'year':
|
|
147
|
+
if (newValue > new Date().getFullYear()) {
|
|
148
|
+
this.setState({
|
|
149
|
+
year: new Date().getFullYear().toString()
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
this.setState({
|
|
153
|
+
year: newValue
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// After setting the state, create a new date using the updated values.
|
|
162
|
+
var updatedMonth = event.target.name === 'month' ? newValue : month;
|
|
163
|
+
var updatedDay = event.target.name === 'day' ? newValue : day;
|
|
164
|
+
var updatedYear = event.target.name === 'year' ? newValue : year;
|
|
165
|
+
if (updatedMonth && updatedDay && updatedYear) {
|
|
166
|
+
var newDate = new Date("".concat(updatedYear, "-").concat(updatedMonth, "-").concat(updatedDay));
|
|
167
|
+
this.handleChange({
|
|
168
|
+
value: newDate
|
|
169
|
+
});
|
|
117
170
|
}
|
|
118
|
-
this.setState((0, _defineProperty2["default"])({}, event.target.name, value));
|
|
119
171
|
}
|
|
120
172
|
}, {
|
|
121
173
|
key: "render",
|
|
@@ -174,8 +226,7 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
174
226
|
className: "form-control",
|
|
175
227
|
type: "text",
|
|
176
228
|
style: {
|
|
177
|
-
border: 'none'
|
|
178
|
-
fontFamily: 'Oswald'
|
|
229
|
+
border: 'none'
|
|
179
230
|
},
|
|
180
231
|
onFocus: function onFocus(e) {
|
|
181
232
|
return _this2.handleBirthdayFocus();
|
|
@@ -198,8 +249,7 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
198
249
|
className: "form-control",
|
|
199
250
|
type: "text",
|
|
200
251
|
style: {
|
|
201
|
-
border: 'none'
|
|
202
|
-
fontFamily: 'Oswald'
|
|
252
|
+
border: 'none'
|
|
203
253
|
},
|
|
204
254
|
onChange: function onChange(e) {
|
|
205
255
|
return _this2.handleDateChange(e);
|
|
@@ -221,8 +271,7 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
221
271
|
className: "form-control",
|
|
222
272
|
type: "text",
|
|
223
273
|
style: {
|
|
224
|
-
border: 'none'
|
|
225
|
-
fontFamily: 'Oswald'
|
|
274
|
+
border: 'none'
|
|
226
275
|
},
|
|
227
276
|
onFocus: function onFocus(e) {
|
|
228
277
|
return _this2.handleBirthdayFocus();
|