@progress/kendo-react-form 6.1.1 → 7.0.0-develop.1
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/es/Field.d.ts → Field.d.ts} +4 -0
- package/FieldArray.d.ts +11 -0
- package/{dist/es/FieldWrapper.d.ts → FieldWrapper.d.ts} +4 -0
- package/{dist/es/Form.d.ts → Form.d.ts} +5 -1
- package/{dist/es/FormContext.d.ts → FormContext.d.ts} +5 -1
- package/{dist/es/FormElement.d.ts → FormElement.d.ts} +4 -0
- package/LICENSE.md +1 -1
- package/dist/cdn/js/kendo-react-form.js +5 -1
- package/index.d.ts +20 -0
- package/index.js +5 -0
- package/index.mjs +409 -0
- package/{dist/npm/interfaces → interfaces}/FieldArrayProps.d.ts +4 -1
- package/{dist/npm/interfaces → interfaces}/FieldArrayRenderProps.d.ts +4 -0
- package/{dist/npm/interfaces → interfaces}/FieldProps.d.ts +4 -1
- package/{dist/es/interfaces → interfaces}/FieldRenderProps.d.ts +4 -0
- package/{dist/es/interfaces → interfaces}/FieldValidator.d.ts +5 -1
- package/{dist/es/interfaces → interfaces}/FormProps.d.ts +4 -1
- package/{dist/npm/interfaces → interfaces}/FormRenderProps.d.ts +4 -1
- package/{dist/npm/interfaces → interfaces}/FormSubmitClickEvent.d.ts +4 -1
- package/interfaces/FormValidator.d.ts +14 -0
- package/interfaces/KeyValue.d.ts +10 -0
- package/package-metadata.d.ts +9 -0
- package/package.json +26 -42
- package/about.md +0 -3
- package/dist/es/Field.js +0 -92
- package/dist/es/FieldArray.d.ts +0 -7
- package/dist/es/FieldArray.js +0 -72
- package/dist/es/FieldWrapper.js +0 -15
- package/dist/es/Form.js +0 -607
- package/dist/es/FormContext.js +0 -3
- package/dist/es/FormElement.js +0 -49
- package/dist/es/interfaces/FieldArrayProps.d.ts +0 -29
- package/dist/es/interfaces/FieldArrayProps.js +0 -1
- package/dist/es/interfaces/FieldArrayRenderProps.d.ts +0 -89
- package/dist/es/interfaces/FieldArrayRenderProps.js +0 -1
- package/dist/es/interfaces/FieldProps.d.ts +0 -40
- package/dist/es/interfaces/FieldProps.js +0 -1
- package/dist/es/interfaces/FieldRenderProps.js +0 -1
- package/dist/es/interfaces/FieldValidator.js +0 -1
- package/dist/es/interfaces/FormProps.js +0 -1
- package/dist/es/interfaces/FormRenderProps.d.ts +0 -75
- package/dist/es/interfaces/FormRenderProps.js +0 -1
- package/dist/es/interfaces/FormSubmitClickEvent.d.ts +0 -24
- package/dist/es/interfaces/FormSubmitClickEvent.js +0 -1
- package/dist/es/interfaces/FormValidator.d.ts +0 -10
- package/dist/es/interfaces/FormValidator.js +0 -1
- package/dist/es/interfaces/KeyValue.d.ts +0 -6
- package/dist/es/interfaces/KeyValue.js +0 -1
- package/dist/es/main.d.ts +0 -16
- package/dist/es/main.js +0 -6
- package/dist/es/package-metadata.d.ts +0 -5
- package/dist/es/package-metadata.js +0 -11
- package/dist/npm/Field.d.ts +0 -10
- package/dist/npm/Field.js +0 -96
- package/dist/npm/FieldArray.d.ts +0 -7
- package/dist/npm/FieldArray.js +0 -76
- package/dist/npm/FieldWrapper.d.ts +0 -28
- package/dist/npm/FieldWrapper.js +0 -19
- package/dist/npm/Form.d.ts +0 -262
- package/dist/npm/Form.js +0 -610
- package/dist/npm/FormContext.d.ts +0 -50
- package/dist/npm/FormContext.js +0 -6
- package/dist/npm/FormElement.d.ts +0 -52
- package/dist/npm/FormElement.js +0 -52
- package/dist/npm/interfaces/FieldArrayProps.js +0 -2
- package/dist/npm/interfaces/FieldArrayRenderProps.js +0 -2
- package/dist/npm/interfaces/FieldProps.js +0 -2
- package/dist/npm/interfaces/FieldRenderProps.d.ts +0 -65
- package/dist/npm/interfaces/FieldRenderProps.js +0 -2
- package/dist/npm/interfaces/FieldValidator.d.ts +0 -14
- package/dist/npm/interfaces/FieldValidator.js +0 -2
- package/dist/npm/interfaces/FormProps.d.ts +0 -47
- package/dist/npm/interfaces/FormProps.js +0 -2
- package/dist/npm/interfaces/FormRenderProps.js +0 -2
- package/dist/npm/interfaces/FormSubmitClickEvent.js +0 -2
- package/dist/npm/interfaces/FormValidator.d.ts +0 -10
- package/dist/npm/interfaces/FormValidator.js +0 -2
- package/dist/npm/interfaces/KeyValue.d.ts +0 -6
- package/dist/npm/interfaces/KeyValue.js +0 -2
- package/dist/npm/main.d.ts +0 -16
- package/dist/npm/main.js +0 -13
- package/dist/npm/package-metadata.d.ts +0 -5
- package/dist/npm/package-metadata.js +0 -14
- package/dist/systemjs/kendo-react-form.js +0 -1
- package/e2e-next/form.basic.tests.ts +0 -23
package/dist/es/Form.js
DELETED
|
@@ -1,607 +0,0 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
|
-
var __assign = (this && this.__assign) || function () {
|
|
17
|
-
__assign = Object.assign || function(t) {
|
|
18
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
-
s = arguments[i];
|
|
20
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
-
t[p] = s[p];
|
|
22
|
-
}
|
|
23
|
-
return t;
|
|
24
|
-
};
|
|
25
|
-
return __assign.apply(this, arguments);
|
|
26
|
-
};
|
|
27
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
28
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
-
if (ar || !(i in from)) {
|
|
30
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
-
ar[i] = from[i];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
-
};
|
|
36
|
-
import * as React from 'react';
|
|
37
|
-
import * as PropTypes from 'prop-types';
|
|
38
|
-
import { FormContext } from './FormContext';
|
|
39
|
-
import { getter, setter, clone, cloneObject, guid } from '@progress/kendo-react-common';
|
|
40
|
-
import { validatePackage } from '@progress/kendo-react-common';
|
|
41
|
-
import { packageMetadata } from './package-metadata';
|
|
42
|
-
/**
|
|
43
|
-
* @hidden
|
|
44
|
-
*/
|
|
45
|
-
var FORCEUPDATE_ACCUMULATOR_TIMEOUT = 0;
|
|
46
|
-
/**
|
|
47
|
-
* Represents the [KendoReact Form component]({% slug overview_form %}).
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```jsx
|
|
51
|
-
* export const FormInput = (fieldRenderProps) => {
|
|
52
|
-
* const onValueChange = React.useCallback(
|
|
53
|
-
* (event) => fieldRenderProps.onChange(event.target.value),
|
|
54
|
-
* [fieldRenderProps.onChange]
|
|
55
|
-
* );
|
|
56
|
-
* return (
|
|
57
|
-
* <input
|
|
58
|
-
* className={'k-input'}
|
|
59
|
-
* value={fieldRenderProps.value}
|
|
60
|
-
* onChange={onValueChange}
|
|
61
|
-
* />
|
|
62
|
-
* );
|
|
63
|
-
* };
|
|
64
|
-
*
|
|
65
|
-
* export const App = () => {
|
|
66
|
-
* const handleSubmit = (dataItem) => alert(JSON.stringify(dataItem));
|
|
67
|
-
* return (
|
|
68
|
-
* <Form
|
|
69
|
-
* initialValues={{title: ''}}
|
|
70
|
-
* onSubmit={handleSubmit}
|
|
71
|
-
* render={(formRenderProps) => (
|
|
72
|
-
* <div>
|
|
73
|
-
* <Field name={'title'} component={FormInput} />
|
|
74
|
-
* <button
|
|
75
|
-
* className="k-button"
|
|
76
|
-
* disabled={!formRenderProps.allowSubmit}
|
|
77
|
-
* onClick={formRenderProps.onSubmit}
|
|
78
|
-
* >
|
|
79
|
-
* Submit
|
|
80
|
-
* </button>
|
|
81
|
-
* </div>
|
|
82
|
-
* )}
|
|
83
|
-
* />
|
|
84
|
-
* );
|
|
85
|
-
* };
|
|
86
|
-
*
|
|
87
|
-
* ReactDOM.render(<App />, document.querySelector('my-app'));
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
var Form = /** @class */ (function (_super) {
|
|
91
|
-
__extends(Form, _super);
|
|
92
|
-
/**
|
|
93
|
-
* @hidden
|
|
94
|
-
*/
|
|
95
|
-
function Form(props) {
|
|
96
|
-
var _this = _super.call(this, props) || this;
|
|
97
|
-
_this._id = guid();
|
|
98
|
-
_this._touched = {};
|
|
99
|
-
_this._visited = {};
|
|
100
|
-
_this._modified = {};
|
|
101
|
-
_this._validatorsByField = {};
|
|
102
|
-
_this._values = {};
|
|
103
|
-
_this._fields = {};
|
|
104
|
-
_this._unmounted = false;
|
|
105
|
-
_this._submitted = false;
|
|
106
|
-
/**
|
|
107
|
-
* @hidden
|
|
108
|
-
*/
|
|
109
|
-
_this.isValid = function () {
|
|
110
|
-
return _this.isFormValid(_this.errors);
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* @hidden
|
|
114
|
-
*/
|
|
115
|
-
_this.accumulatedForceUpdate = function () {
|
|
116
|
-
// IMPORTANT:
|
|
117
|
-
// Should only be used for updates not comming from editors as it
|
|
118
|
-
// will cause cursor jump as react will reset the editor to old value
|
|
119
|
-
if (_this._accumulatorTimeout) {
|
|
120
|
-
clearTimeout(_this._accumulatorTimeout);
|
|
121
|
-
}
|
|
122
|
-
_this._accumulatorTimeout = window.setTimeout(function () {
|
|
123
|
-
_this._accumulatorTimeout = undefined;
|
|
124
|
-
_this.forceUpdate();
|
|
125
|
-
}, FORCEUPDATE_ACCUMULATOR_TIMEOUT);
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* @hidden
|
|
129
|
-
*/
|
|
130
|
-
_this.resetForm = function () {
|
|
131
|
-
_this.values = clone(_this.props.initialValues);
|
|
132
|
-
_this._id = guid();
|
|
133
|
-
_this._touched = {};
|
|
134
|
-
_this._visited = {};
|
|
135
|
-
_this._modified = {};
|
|
136
|
-
_this._validatorsByField = {};
|
|
137
|
-
_this._fields = {};
|
|
138
|
-
_this._submitted = false;
|
|
139
|
-
_this.forceUpdate();
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Method for resetting the form state outside the form component.
|
|
143
|
-
*
|
|
144
|
-
* > Use `onReset` only if you cannot achieve the desired behavior through the Field component or by FormRenderProps.
|
|
145
|
-
*/
|
|
146
|
-
_this.onReset = function () { return _this.resetForm(); };
|
|
147
|
-
/**
|
|
148
|
-
* @hidden
|
|
149
|
-
*/
|
|
150
|
-
_this.addField = function (field) {
|
|
151
|
-
_this._fields[field] = true;
|
|
152
|
-
};
|
|
153
|
-
/**
|
|
154
|
-
* @hidden
|
|
155
|
-
*/
|
|
156
|
-
_this.onSubmit = function (event) {
|
|
157
|
-
var touchedVisited = {};
|
|
158
|
-
var fields = _this.fields;
|
|
159
|
-
if (event) {
|
|
160
|
-
if (typeof event.preventDefault === 'function') {
|
|
161
|
-
event.preventDefault();
|
|
162
|
-
}
|
|
163
|
-
if (typeof event.stopPropagation === 'function') {
|
|
164
|
-
event.stopPropagation();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
fields.forEach(function (fieldName) {
|
|
168
|
-
touchedVisited[fieldName] = true;
|
|
169
|
-
});
|
|
170
|
-
// show validations
|
|
171
|
-
_this.visited = __assign({}, touchedVisited);
|
|
172
|
-
_this.touched = __assign({}, touchedVisited);
|
|
173
|
-
var values = _this.values;
|
|
174
|
-
var isValid = _this.isFormValid(_this.errors);
|
|
175
|
-
var isModified = _this.isFormModified(_this.modified, fields);
|
|
176
|
-
if (_this.props.onSubmitClick) {
|
|
177
|
-
_this.props.onSubmitClick.call(undefined, {
|
|
178
|
-
values: values,
|
|
179
|
-
isValid: isValid,
|
|
180
|
-
isModified: isModified,
|
|
181
|
-
event: event
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
if (isValid && (_this.props.ignoreModified || isModified) && _this.props.onSubmit) {
|
|
185
|
-
_this._submitted = true;
|
|
186
|
-
_this.props.onSubmit.call(undefined, values, event);
|
|
187
|
-
}
|
|
188
|
-
_this.forceUpdate();
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* Method for emiting changes to a specific field outside the form component.
|
|
192
|
-
*
|
|
193
|
-
* > Use `onChange` only if you cannot achieve the desired behavior through the Field component by FormRenderProps.
|
|
194
|
-
*/
|
|
195
|
-
_this.onChange = function (name, options) {
|
|
196
|
-
var _a;
|
|
197
|
-
var value = options.value;
|
|
198
|
-
_this.addField(name);
|
|
199
|
-
if (!_this.modified[name]) {
|
|
200
|
-
_this.modified = __assign(__assign({}, _this.modified), (_a = {}, _a[name] = true, _a));
|
|
201
|
-
}
|
|
202
|
-
_this.valueSetter(name, value);
|
|
203
|
-
_this.forceUpdate();
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* @hidden
|
|
207
|
-
*/
|
|
208
|
-
_this.onFocus = function (name, skipForceUpdate) {
|
|
209
|
-
var _a;
|
|
210
|
-
if (_this.visited[name]) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
_this.visited = __assign(__assign({}, _this.visited), (_a = {}, _a[name] = true, _a));
|
|
214
|
-
if (!skipForceUpdate) {
|
|
215
|
-
_this.forceUpdate();
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
/**
|
|
219
|
-
* @hidden
|
|
220
|
-
*/
|
|
221
|
-
_this.onBlur = function (name, skipForceUpdate) {
|
|
222
|
-
var _a;
|
|
223
|
-
if (_this.touched[name]) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
_this.onFocus(name, skipForceUpdate);
|
|
227
|
-
_this.touched = __assign(__assign({}, _this.touched), (_a = {}, _a[name] = true, _a));
|
|
228
|
-
if (!skipForceUpdate) {
|
|
229
|
-
_this.forceUpdate();
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
/**
|
|
233
|
-
* @hidden
|
|
234
|
-
*/
|
|
235
|
-
_this.onFieldRegister = function (name, validator) {
|
|
236
|
-
var _a;
|
|
237
|
-
_this.addField(name);
|
|
238
|
-
// The sole reason for using class props over state - nextIndex, needed for destroying validators
|
|
239
|
-
var oldValidators = (_this.validatorsByField[name] || []);
|
|
240
|
-
var nextIndex = oldValidators.length;
|
|
241
|
-
_this.validatorsByField = __assign(__assign({}, _this.validatorsByField), (_a = {}, _a[name] = __spreadArray(__spreadArray([], oldValidators, true), [validator], false), _a));
|
|
242
|
-
_this.accumulatedForceUpdate();
|
|
243
|
-
return function () {
|
|
244
|
-
var _a;
|
|
245
|
-
// onFieldUnregister:
|
|
246
|
-
if (_this._unmounted) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
var newValidators = __spreadArray([], (_this.validatorsByField[name] || []), true);
|
|
250
|
-
var validatorIsUnregistered = Boolean(newValidators[nextIndex]);
|
|
251
|
-
newValidators[nextIndex] = undefined;
|
|
252
|
-
_this.validatorsByField = __assign(__assign({}, _this.validatorsByField), (_a = {}, _a[name] = newValidators, _a));
|
|
253
|
-
if (validatorIsUnregistered) {
|
|
254
|
-
_this.accumulatedForceUpdate();
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
};
|
|
258
|
-
/**
|
|
259
|
-
* @hidden
|
|
260
|
-
*/
|
|
261
|
-
_this.isFormValid = function (errors) {
|
|
262
|
-
return !Object.keys(errors).some(function (fieldName) { return Boolean(errors[fieldName]); });
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* @hidden
|
|
266
|
-
*/
|
|
267
|
-
_this.isFormModified = function (modified, fields) {
|
|
268
|
-
return fields.some(function (fieldName) { return modified[fieldName]; });
|
|
269
|
-
};
|
|
270
|
-
/**
|
|
271
|
-
* @hidden
|
|
272
|
-
*/
|
|
273
|
-
_this.isFormHasNotTouched = function (touched, fields) {
|
|
274
|
-
return fields.some(function (fieldName) { return !touched[fieldName]; });
|
|
275
|
-
};
|
|
276
|
-
/**
|
|
277
|
-
* @hidden
|
|
278
|
-
*/
|
|
279
|
-
_this.isFormTouched = function (touched, fields) {
|
|
280
|
-
return fields.some(function (fieldName) { return touched[fieldName]; });
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* @hidden
|
|
284
|
-
*/
|
|
285
|
-
_this.isFormVisited = function (visited, fields) {
|
|
286
|
-
return fields.some(function (fieldName) { return visited[fieldName]; });
|
|
287
|
-
};
|
|
288
|
-
/**
|
|
289
|
-
* @hidden
|
|
290
|
-
*/
|
|
291
|
-
_this.valueGetter = function (fieldName) {
|
|
292
|
-
return getter(fieldName)(_this.values);
|
|
293
|
-
};
|
|
294
|
-
/**
|
|
295
|
-
* @hidden
|
|
296
|
-
*/
|
|
297
|
-
_this.valueSetter = function (fieldName, value) {
|
|
298
|
-
return setter(fieldName)(_this.values, value);
|
|
299
|
-
};
|
|
300
|
-
/**
|
|
301
|
-
* @hidden
|
|
302
|
-
*/
|
|
303
|
-
_this.onArrayAction = function (name) {
|
|
304
|
-
var _a;
|
|
305
|
-
_this.addField(name);
|
|
306
|
-
if (!_this.modified[name]) {
|
|
307
|
-
_this.modified = __assign(__assign({}, _this.modified), (_a = {}, _a[name] = true, _a));
|
|
308
|
-
}
|
|
309
|
-
_this.onBlur(name, true);
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* @hidden
|
|
313
|
-
*/
|
|
314
|
-
_this.onInsert = function (name, options) {
|
|
315
|
-
_this.onArrayAction(name);
|
|
316
|
-
var newArray = __spreadArray([], (_this.valueGetter(name) || []), true);
|
|
317
|
-
newArray.splice(options.index, 0, options.value);
|
|
318
|
-
_this.valueSetter(name, newArray);
|
|
319
|
-
_this.forceUpdate();
|
|
320
|
-
};
|
|
321
|
-
/**
|
|
322
|
-
* @hidden
|
|
323
|
-
*/
|
|
324
|
-
_this.onUnshift = function (name, options) {
|
|
325
|
-
_this.onInsert(name, {
|
|
326
|
-
value: options.value,
|
|
327
|
-
index: 0
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* @hidden
|
|
332
|
-
*/
|
|
333
|
-
_this.onPush = function (name, options) {
|
|
334
|
-
_this.onArrayAction(name);
|
|
335
|
-
var newArray = __spreadArray(__spreadArray([], (_this.valueGetter(name) || []), true), [options.value], false);
|
|
336
|
-
_this.valueSetter(name, newArray);
|
|
337
|
-
_this.forceUpdate();
|
|
338
|
-
};
|
|
339
|
-
/**
|
|
340
|
-
* @hidden
|
|
341
|
-
*/
|
|
342
|
-
_this.onPop = function (name) {
|
|
343
|
-
_this.onArrayAction(name);
|
|
344
|
-
var newArray = __spreadArray([], (_this.valueGetter(name) || []), true);
|
|
345
|
-
var value = newArray.pop();
|
|
346
|
-
_this.valueSetter(name, newArray);
|
|
347
|
-
_this.forceUpdate();
|
|
348
|
-
return value;
|
|
349
|
-
};
|
|
350
|
-
/**
|
|
351
|
-
* @hidden
|
|
352
|
-
*/
|
|
353
|
-
_this.onRemove = function (name, options) {
|
|
354
|
-
_this.onArrayAction(name);
|
|
355
|
-
var newArray = __spreadArray([], (_this.valueGetter(name) || []), true);
|
|
356
|
-
var value = newArray.splice(options.index, 1);
|
|
357
|
-
_this.valueSetter(name, newArray);
|
|
358
|
-
_this.forceUpdate();
|
|
359
|
-
return value;
|
|
360
|
-
};
|
|
361
|
-
/**
|
|
362
|
-
* @hidden
|
|
363
|
-
*/
|
|
364
|
-
_this.onReplace = function (name, options) {
|
|
365
|
-
_this.onArrayAction(name);
|
|
366
|
-
var newArray = __spreadArray([], (_this.valueGetter(name) || []), true);
|
|
367
|
-
newArray.splice(options.index, 1, options.value);
|
|
368
|
-
_this.valueSetter(name, newArray);
|
|
369
|
-
_this.forceUpdate();
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* @hidden
|
|
373
|
-
*/
|
|
374
|
-
_this.onMove = function (name, options) {
|
|
375
|
-
_this.onArrayAction(name);
|
|
376
|
-
var newArray = __spreadArray([], (_this.valueGetter(name) || []), true);
|
|
377
|
-
var value = newArray[options.prevIndex];
|
|
378
|
-
newArray.splice(options.prevIndex, 1);
|
|
379
|
-
newArray.splice(options.nextIndex, 0, value);
|
|
380
|
-
_this.valueSetter(name, newArray);
|
|
381
|
-
_this.forceUpdate();
|
|
382
|
-
};
|
|
383
|
-
validatePackage(packageMetadata);
|
|
384
|
-
_this.values = clone(props.initialValues);
|
|
385
|
-
return _this;
|
|
386
|
-
}
|
|
387
|
-
Object.defineProperty(Form.prototype, "touched", {
|
|
388
|
-
/**
|
|
389
|
-
* @hidden
|
|
390
|
-
*/
|
|
391
|
-
get: function () {
|
|
392
|
-
return this._touched;
|
|
393
|
-
},
|
|
394
|
-
/**
|
|
395
|
-
* @hidden
|
|
396
|
-
*/
|
|
397
|
-
set: function (value) {
|
|
398
|
-
this._touched = value;
|
|
399
|
-
},
|
|
400
|
-
enumerable: false,
|
|
401
|
-
configurable: true
|
|
402
|
-
});
|
|
403
|
-
Object.defineProperty(Form.prototype, "visited", {
|
|
404
|
-
/**
|
|
405
|
-
* @hidden
|
|
406
|
-
*/
|
|
407
|
-
get: function () {
|
|
408
|
-
return this._visited;
|
|
409
|
-
},
|
|
410
|
-
/**
|
|
411
|
-
* @hidden
|
|
412
|
-
*/
|
|
413
|
-
set: function (value) {
|
|
414
|
-
this._visited = value;
|
|
415
|
-
},
|
|
416
|
-
enumerable: false,
|
|
417
|
-
configurable: true
|
|
418
|
-
});
|
|
419
|
-
Object.defineProperty(Form.prototype, "modified", {
|
|
420
|
-
/**
|
|
421
|
-
* @hidden
|
|
422
|
-
*/
|
|
423
|
-
get: function () {
|
|
424
|
-
return this._modified;
|
|
425
|
-
},
|
|
426
|
-
/**
|
|
427
|
-
* @hidden
|
|
428
|
-
*/
|
|
429
|
-
set: function (value) {
|
|
430
|
-
this._modified = value;
|
|
431
|
-
},
|
|
432
|
-
enumerable: false,
|
|
433
|
-
configurable: true
|
|
434
|
-
});
|
|
435
|
-
Object.defineProperty(Form.prototype, "validatorsByField", {
|
|
436
|
-
/**
|
|
437
|
-
* @hidden
|
|
438
|
-
*/
|
|
439
|
-
get: function () {
|
|
440
|
-
return this._validatorsByField;
|
|
441
|
-
},
|
|
442
|
-
/**
|
|
443
|
-
* @hidden
|
|
444
|
-
*/
|
|
445
|
-
set: function (value) {
|
|
446
|
-
this._validatorsByField = value;
|
|
447
|
-
},
|
|
448
|
-
enumerable: false,
|
|
449
|
-
configurable: true
|
|
450
|
-
});
|
|
451
|
-
Object.defineProperty(Form.prototype, "values", {
|
|
452
|
-
/**
|
|
453
|
-
* @hidden
|
|
454
|
-
*/
|
|
455
|
-
get: function () {
|
|
456
|
-
return this._values;
|
|
457
|
-
},
|
|
458
|
-
/**
|
|
459
|
-
* @hidden
|
|
460
|
-
*/
|
|
461
|
-
set: function (value) {
|
|
462
|
-
this._values = value;
|
|
463
|
-
},
|
|
464
|
-
enumerable: false,
|
|
465
|
-
configurable: true
|
|
466
|
-
});
|
|
467
|
-
Object.defineProperty(Form.prototype, "fields", {
|
|
468
|
-
/**
|
|
469
|
-
* @hidden
|
|
470
|
-
*/
|
|
471
|
-
get: function () {
|
|
472
|
-
return Object.keys(this._fields);
|
|
473
|
-
},
|
|
474
|
-
enumerable: false,
|
|
475
|
-
configurable: true
|
|
476
|
-
});
|
|
477
|
-
Object.defineProperty(Form.prototype, "formErrors", {
|
|
478
|
-
/**
|
|
479
|
-
* @hidden
|
|
480
|
-
*/
|
|
481
|
-
get: function () {
|
|
482
|
-
if (this.props.validator) {
|
|
483
|
-
return this.props.validator(this.values, this.valueGetter);
|
|
484
|
-
}
|
|
485
|
-
},
|
|
486
|
-
enumerable: false,
|
|
487
|
-
configurable: true
|
|
488
|
-
});
|
|
489
|
-
Object.defineProperty(Form.prototype, "errors", {
|
|
490
|
-
/**
|
|
491
|
-
* @hidden
|
|
492
|
-
*/
|
|
493
|
-
get: function () {
|
|
494
|
-
var _this = this;
|
|
495
|
-
var errors = {};
|
|
496
|
-
var fields = this.fields;
|
|
497
|
-
var validatorsByField = this.validatorsByField;
|
|
498
|
-
fields.forEach(function (fieldName) {
|
|
499
|
-
errors[fieldName] = '';
|
|
500
|
-
if (validatorsByField[fieldName]) {
|
|
501
|
-
var validators_1 = [];
|
|
502
|
-
validatorsByField[fieldName].forEach(function (validator) {
|
|
503
|
-
if (Array.isArray(validator)) {
|
|
504
|
-
validators_1.push.apply(validators_1, validator);
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
validators_1.push(validator);
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
// find first validation error
|
|
511
|
-
validators_1.find(function (validator) {
|
|
512
|
-
if (validator) {
|
|
513
|
-
var result = validator(_this.valueGetter(fieldName), _this.valueGetter, { name: fieldName });
|
|
514
|
-
if (result) {
|
|
515
|
-
errors[fieldName] = result;
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return false;
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
var formErrors = this.formErrors;
|
|
524
|
-
if (formErrors) {
|
|
525
|
-
cloneObject(this.formErrors, errors);
|
|
526
|
-
}
|
|
527
|
-
return errors;
|
|
528
|
-
},
|
|
529
|
-
enumerable: false,
|
|
530
|
-
configurable: true
|
|
531
|
-
});
|
|
532
|
-
/**
|
|
533
|
-
* @hidden
|
|
534
|
-
*/
|
|
535
|
-
Form.prototype.componentWillUnmount = function () {
|
|
536
|
-
this._unmounted = true;
|
|
537
|
-
if (this._accumulatorTimeout) {
|
|
538
|
-
clearTimeout(this._accumulatorTimeout);
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
/**
|
|
542
|
-
* @hidden
|
|
543
|
-
*/
|
|
544
|
-
Form.prototype.render = function () {
|
|
545
|
-
var render = this.props.render;
|
|
546
|
-
var touched = this.touched;
|
|
547
|
-
var visited = this.visited;
|
|
548
|
-
var modified = this.modified;
|
|
549
|
-
var fields = this.fields;
|
|
550
|
-
var errors = this.errors;
|
|
551
|
-
var formValid = this.isFormValid(errors);
|
|
552
|
-
var formModified = this.isFormModified(modified, fields);
|
|
553
|
-
var formTouched = this.isFormTouched(touched, fields);
|
|
554
|
-
var formVisited = this.isFormVisited(visited, fields);
|
|
555
|
-
var formHasNotTouched = this.isFormHasNotTouched(touched, fields);
|
|
556
|
-
// 1. The form is not touched, but has errors - allow submit to force validation.
|
|
557
|
-
// 2. The form is valid and modified - if not modified, disable submit.
|
|
558
|
-
var allowSubmit = (formHasNotTouched && !formValid) || (formValid && (this.props.ignoreModified || formModified));
|
|
559
|
-
return (React.createElement(FormContext.Provider, { key: this._id, value: {
|
|
560
|
-
id: this._id,
|
|
561
|
-
valueGetter: this.valueGetter,
|
|
562
|
-
errors: errors,
|
|
563
|
-
modified: modified,
|
|
564
|
-
touched: touched,
|
|
565
|
-
visited: visited,
|
|
566
|
-
registerField: this.onFieldRegister,
|
|
567
|
-
onSubmit: this.onSubmit,
|
|
568
|
-
onChange: this.onChange,
|
|
569
|
-
onFocus: this.onFocus,
|
|
570
|
-
onBlur: this.onBlur,
|
|
571
|
-
onUnshift: this.onUnshift,
|
|
572
|
-
onPush: this.onPush,
|
|
573
|
-
onInsert: this.onInsert,
|
|
574
|
-
onPop: this.onPop,
|
|
575
|
-
onRemove: this.onRemove,
|
|
576
|
-
onReplace: this.onReplace,
|
|
577
|
-
onMove: this.onMove
|
|
578
|
-
} }, render({
|
|
579
|
-
valid: formValid,
|
|
580
|
-
modified: formModified,
|
|
581
|
-
touched: formTouched,
|
|
582
|
-
visited: formVisited,
|
|
583
|
-
submitted: this._submitted,
|
|
584
|
-
valueGetter: this.valueGetter,
|
|
585
|
-
errors: errors,
|
|
586
|
-
allowSubmit: allowSubmit,
|
|
587
|
-
onChange: this.onChange,
|
|
588
|
-
onSubmit: this.onSubmit,
|
|
589
|
-
onFormReset: this.resetForm
|
|
590
|
-
})));
|
|
591
|
-
};
|
|
592
|
-
/**
|
|
593
|
-
* @hidden
|
|
594
|
-
*/
|
|
595
|
-
Form.displayName = 'KendoReactForm';
|
|
596
|
-
/**
|
|
597
|
-
* @hidden
|
|
598
|
-
*/
|
|
599
|
-
Form.propTypes = {
|
|
600
|
-
initialValues: PropTypes.any,
|
|
601
|
-
onSubmit: PropTypes.func,
|
|
602
|
-
onSubmitClick: PropTypes.func,
|
|
603
|
-
render: PropTypes.func.isRequired
|
|
604
|
-
};
|
|
605
|
-
return Form;
|
|
606
|
-
}(React.Component));
|
|
607
|
-
export { Form };
|
package/dist/es/FormContext.js
DELETED
package/dist/es/FormElement.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
import * as React from 'react';
|
|
24
|
-
import { classNames, kendoThemeMaps } from '@progress/kendo-react-common';
|
|
25
|
-
import { FormContext } from './FormContext';
|
|
26
|
-
/**
|
|
27
|
-
* Represents the KendoReact FormElement component.
|
|
28
|
-
* It's small wrapper around HTML form element which automatically attach the
|
|
29
|
-
* Form component's `onSubmit` render prop and Kendo CSS classes.
|
|
30
|
-
* Other props are passed to the DOM node.
|
|
31
|
-
*/
|
|
32
|
-
export var FormElement = React.forwardRef(function (props, ref) {
|
|
33
|
-
var _a;
|
|
34
|
-
var combinedProps = __assign({ size: 'medium' }, props);
|
|
35
|
-
var element = React.useRef(null);
|
|
36
|
-
var target = React.useRef(null);
|
|
37
|
-
React.useImperativeHandle(target, function () { return ({ element: element.current, props: combinedProps }); });
|
|
38
|
-
React.useImperativeHandle(ref, function () { return target.current; });
|
|
39
|
-
var form = React.useContext(FormContext);
|
|
40
|
-
var className = combinedProps.className, style = combinedProps.style, horizontal = combinedProps.horizontal, size = combinedProps.size, others = __rest(combinedProps, ["className", "style", "horizontal", "size"]);
|
|
41
|
-
var formClassName = classNames((_a = {
|
|
42
|
-
'k-form': true
|
|
43
|
-
},
|
|
44
|
-
_a["k-form-".concat(kendoThemeMaps.sizeMap[size] || size)] = size,
|
|
45
|
-
_a['k-form-horizontal'] = horizontal === true,
|
|
46
|
-
_a), className);
|
|
47
|
-
return (React.createElement("form", __assign({ ref: element }, others, { style: props.style, className: formClassName, onSubmit: form ? form.onSubmit : undefined }), props.children));
|
|
48
|
-
});
|
|
49
|
-
FormElement.displayName = 'KendoReactFormElement';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { FieldValidatorType } from './FieldValidator';
|
|
3
|
-
/**
|
|
4
|
-
* Represents the props of the FieldArray component that is used inside the KendoReact Form component.
|
|
5
|
-
*/
|
|
6
|
-
export interface FieldArrayProps {
|
|
7
|
-
/**
|
|
8
|
-
* The name of the field in the Form state.
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
/**
|
|
12
|
-
* Can be set to a React component.
|
|
13
|
-
* [`FieldArrayRenderProps`]({% slug api_form_fieldarrayrenderprops %}).
|
|
14
|
-
*/
|
|
15
|
-
component: React.ComponentType<any>;
|
|
16
|
-
/**
|
|
17
|
-
* The validation functions for the FieldArray level.
|
|
18
|
-
* Currently, `validator` supports only synchronous functions.
|
|
19
|
-
*/
|
|
20
|
-
validator?: FieldValidatorType | FieldValidatorType[];
|
|
21
|
-
/**
|
|
22
|
-
* The React elements that are passed as children to the rendered component.
|
|
23
|
-
*/
|
|
24
|
-
children?: any;
|
|
25
|
-
/**
|
|
26
|
-
* @hidden
|
|
27
|
-
*/
|
|
28
|
-
[customProp: string]: any;
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|