react-form-builder-more-flexibility 1.0.11 → 1.0.13
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 +6 -6
- package/lib/form-elements/date-picker.js +68 -44
- package/package.json +3 -2
|
@@ -21,6 +21,24 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
21
21
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
22
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
23
23
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
24
|
+
// This is the utility function that will attempt to parse a date string
|
|
25
|
+
// using several different formats until it finds one that works.
|
|
26
|
+
function parseDate(dateStr, formatMask) {
|
|
27
|
+
var formats = ['yyyy-MM-dd',
|
|
28
|
+
// format updated
|
|
29
|
+
'MM/dd/yyyy', formatMask
|
|
30
|
+
// add any other formats you might need to support
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
var date = formats.find(function (newFormat) {
|
|
34
|
+
var parsedDate = (0, _dateFns.parse)(dateStr, newFormat, new Date());
|
|
35
|
+
return !Number.isNaN(parsedDate.getTime());
|
|
36
|
+
});
|
|
37
|
+
if (date) {
|
|
38
|
+
return (0, _dateFns.parse)(dateStr, date, new Date());
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
24
42
|
var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
25
43
|
(0, _inherits2["default"])(DatePicker, _React$Component);
|
|
26
44
|
var _super = _createSuper(DatePicker);
|
|
@@ -28,21 +46,29 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
28
46
|
var _this;
|
|
29
47
|
(0, _classCallCheck2["default"])(this, DatePicker);
|
|
30
48
|
_this = _super.call(this, props);
|
|
31
|
-
// formatMask = '';
|
|
32
49
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleChange", function (dt) {
|
|
33
50
|
var placeholder;
|
|
34
51
|
var formatMask = _this.state.formatMask;
|
|
52
|
+
var iOSFormatMask = 'yyyy-MM-dd';
|
|
35
53
|
if (dt && dt.target) {
|
|
36
54
|
placeholder = dt && dt.target && dt.target.value === '' ? formatMask.toLowerCase() : '';
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
var dateValue = dt.target.value ? parseDate(dt.target.value, formatMask) : null;
|
|
56
|
+
if (dateValue && Number.isNaN(dateValue)) {
|
|
57
|
+
console.log('Invalid date:', dt.target.value);
|
|
58
|
+
} else {
|
|
59
|
+
var formattedDate = dateValue ? (0, _dateFns.format)(dateValue, iOSFormatMask) : '';
|
|
60
|
+
_this.setState({
|
|
61
|
+
value: formattedDate,
|
|
62
|
+
internalValue: dateValue,
|
|
63
|
+
placeholder: placeholder
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
} else if (dt && Number.isNaN(dt)) {
|
|
67
|
+
console.log('Invalid date:', dt);
|
|
43
68
|
} else {
|
|
69
|
+
var _formattedDate = dt ? (0, _dateFns.format)(dt, iOSFormatMask) : '';
|
|
44
70
|
_this.setState({
|
|
45
|
-
value:
|
|
71
|
+
value: _formattedDate,
|
|
46
72
|
internalValue: dt,
|
|
47
73
|
placeholder: placeholder
|
|
48
74
|
});
|
|
@@ -51,9 +77,14 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
51
77
|
_this.inputField = /*#__PURE__*/_react["default"].createRef();
|
|
52
78
|
var _DatePicker$updateFor = DatePicker.updateFormat(props, null),
|
|
53
79
|
_formatMask = _DatePicker$updateFor.formatMask;
|
|
54
|
-
|
|
80
|
+
var state = DatePicker.updateDateTime(props, {
|
|
55
81
|
formatMask: _formatMask
|
|
56
82
|
}, _formatMask);
|
|
83
|
+
|
|
84
|
+
// Ensure state.value and state.internalValue are not undefined
|
|
85
|
+
state.value = state.value || '';
|
|
86
|
+
state.internalValue = state.internalValue || '';
|
|
87
|
+
_this.state = state;
|
|
57
88
|
return _this;
|
|
58
89
|
}
|
|
59
90
|
(0, _createClass2["default"])(DatePicker, [{
|
|
@@ -96,8 +127,6 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
96
127
|
name: props.name,
|
|
97
128
|
ref: props.ref,
|
|
98
129
|
onChange: this.handleChange,
|
|
99
|
-
dateFormat: "MM/DD/YYYY",
|
|
100
|
-
placeholder: this.state.placeholder,
|
|
101
130
|
value: this.state.value,
|
|
102
131
|
className: "form-control"
|
|
103
132
|
}), !iOS && !readOnly && /*#__PURE__*/_react["default"].createElement(_reactDatepicker["default"], {
|
|
@@ -118,54 +147,50 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
118
147
|
}))));
|
|
119
148
|
}
|
|
120
149
|
}], [{
|
|
121
|
-
key: "updateFormat",
|
|
122
|
-
value: function updateFormat(props, oldFormatMask) {
|
|
123
|
-
var _props$data = props.data,
|
|
124
|
-
showTimeSelect = _props$data.showTimeSelect,
|
|
125
|
-
showTimeSelectOnly = _props$data.showTimeSelectOnly,
|
|
126
|
-
showTimeInput = _props$data.showTimeInput;
|
|
127
|
-
var dateFormat = showTimeSelect && showTimeSelectOnly ? '' : props.data.dateFormat;
|
|
128
|
-
var timeFormat = showTimeSelect || showTimeInput ? props.data.timeFormat : '';
|
|
129
|
-
var formatMask = "".concat(dateFormat, " ").concat(timeFormat).trim();
|
|
130
|
-
var updated = formatMask !== oldFormatMask;
|
|
131
|
-
return {
|
|
132
|
-
updated: updated,
|
|
133
|
-
formatMask: formatMask
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
}, {
|
|
137
150
|
key: "updateDateTime",
|
|
138
151
|
value: function updateDateTime(props, state, formatMask) {
|
|
139
152
|
var value;
|
|
140
153
|
var internalValue;
|
|
141
154
|
var defaultToday = props.data.defaultToday;
|
|
155
|
+
var iOSFormatMask = 'yyyy-MM-dd';
|
|
142
156
|
if (defaultToday && (props.defaultValue === '' || props.defaultValue === undefined)) {
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
var dateToFormat = new Date();
|
|
158
|
+
value = dateToFormat.toString() === 'Invalid Date' ? '' : (0, _dateFns.format)(dateToFormat, iOSFormatMask);
|
|
159
|
+
internalValue = dateToFormat.toString() === 'Invalid Date' ? '' : dateToFormat; // Ensure not undefined
|
|
145
160
|
} else {
|
|
146
|
-
value = props.defaultValue;
|
|
147
|
-
if (value === ''
|
|
148
|
-
internalValue =
|
|
161
|
+
value = props.defaultValue || ''; // Ensure not undefined
|
|
162
|
+
if (value === '') {
|
|
163
|
+
internalValue = '';
|
|
149
164
|
} else {
|
|
150
|
-
|
|
165
|
+
var parsedDate = (0, _dateFns.parse)(value, formatMask, new Date());
|
|
166
|
+
internalValue = parsedDate.toString() === 'Invalid Date' ? '' : parsedDate; // Ensure not undefined
|
|
151
167
|
}
|
|
152
168
|
}
|
|
169
|
+
|
|
153
170
|
return {
|
|
154
171
|
value: value,
|
|
155
172
|
internalValue: internalValue,
|
|
156
173
|
placeholder: formatMask.toLowerCase(),
|
|
157
174
|
defaultToday: defaultToday,
|
|
158
|
-
formatMask:
|
|
175
|
+
formatMask: formatMask
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "updateFormat",
|
|
180
|
+
value: function updateFormat(props, oldFormatMask) {
|
|
181
|
+
var _props$data = props.data,
|
|
182
|
+
showTimeSelect = _props$data.showTimeSelect,
|
|
183
|
+
showTimeSelectOnly = _props$data.showTimeSelectOnly,
|
|
184
|
+
showTimeInput = _props$data.showTimeInput;
|
|
185
|
+
var dateFormat = showTimeSelect && showTimeSelectOnly ? '' : props.data.dateFormat;
|
|
186
|
+
var timeFormat = showTimeSelect || showTimeInput ? props.data.timeFormat : '';
|
|
187
|
+
var formatMask = "".concat(dateFormat, " ").concat(timeFormat).trim();
|
|
188
|
+
var updated = formatMask !== oldFormatMask;
|
|
189
|
+
return {
|
|
190
|
+
updated: updated,
|
|
191
|
+
formatMask: formatMask
|
|
159
192
|
};
|
|
160
193
|
}
|
|
161
|
-
|
|
162
|
-
// componentWillReceiveProps(props) {
|
|
163
|
-
// const formatUpdated = this.updateFormat(props);
|
|
164
|
-
// if ((props.data.defaultToday !== !this.state.defaultToday) || formatUpdated) {
|
|
165
|
-
// const state = this.updateDateTime(props, this.formatMask);
|
|
166
|
-
// this.setState(state);
|
|
167
|
-
// }
|
|
168
|
-
// }
|
|
169
194
|
}, {
|
|
170
195
|
key: "getDerivedStateFromProps",
|
|
171
196
|
value: function getDerivedStateFromProps(props, state) {
|
|
@@ -173,8 +198,7 @@ var DatePicker = /*#__PURE__*/function (_React$Component) {
|
|
|
173
198
|
updated = _DatePicker$updateFor2.updated,
|
|
174
199
|
formatMask = _DatePicker$updateFor2.formatMask;
|
|
175
200
|
if (props.data.defaultToday !== state.defaultToday || updated) {
|
|
176
|
-
|
|
177
|
-
return newState;
|
|
201
|
+
return DatePicker.updateDateTime(props, state, formatMask);
|
|
178
202
|
}
|
|
179
203
|
return null;
|
|
180
204
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-builder-more-flexibility",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "A complete form builder for react.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -103,7 +103,8 @@
|
|
|
103
103
|
"start": "webpack-dev-server --hot --mode development",
|
|
104
104
|
"serve:api": "node server/index.js",
|
|
105
105
|
"pretranspile": "rimraf lib",
|
|
106
|
-
"transpile": "babel --out-dir lib src --copy-files"
|
|
106
|
+
"transpile": "babel --out-dir lib src --copy-files",
|
|
107
|
+
"run-publish": "npm publish"
|
|
107
108
|
},
|
|
108
109
|
"bugs": {
|
|
109
110
|
"url": "https://github.com/ljorgens/react-form-builder/issues"
|