iglooform 2.5.45 → 2.5.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.
- package/es/form/element/index.js +16 -2
- package/es/form/element/style/index.less +8 -0
- package/es/form/hsteps/index.js +61 -26
- package/es/form/index.js +56 -11
- package/es/form/steps/index.js +62 -24
- package/es/form-context.d.ts +1 -0
- package/es/free-form/element/index.js +16 -2
- package/es/free-form/element/style/index.less +8 -0
- package/es/free-form/index.js +62 -13
- package/es/free-form/step/index.d.ts +1 -0
- package/es/free-form/step/index.js +60 -23
- package/es/types.d.ts +3 -0
- package/es/utils/form-utils.d.ts +1 -0
- package/es/utils/form-utils.js +74 -1
- package/es/utils/option-utils.d.ts +1 -0
- package/es/utils/option-utils.js +21 -13
- package/lib/form/element/index.js +17 -2
- package/lib/form/element/style/index.less +8 -0
- package/lib/form/hsteps/index.js +60 -25
- package/lib/form/index.js +57 -10
- package/lib/form/steps/index.js +62 -23
- package/lib/form-context.d.ts +1 -0
- package/lib/free-form/element/index.js +17 -2
- package/lib/free-form/element/style/index.less +8 -0
- package/lib/free-form/index.js +64 -12
- package/lib/free-form/step/index.d.ts +1 -0
- package/lib/free-form/step/index.js +60 -22
- package/lib/types.d.ts +3 -0
- package/lib/utils/form-utils.d.ts +1 -0
- package/lib/utils/form-utils.js +78 -2
- package/lib/utils/option-utils.d.ts +1 -0
- package/lib/utils/option-utils.js +21 -13
- package/package.json +1 -1
package/es/form/element/index.js
CHANGED
|
@@ -47,6 +47,7 @@ import { AlertFilled } from 'iglooicon';
|
|
|
47
47
|
import { calcFormItemProps } from '../../utils/form-utils';
|
|
48
48
|
import Section from '../section';
|
|
49
49
|
import AddableSection from '../addable-section';
|
|
50
|
+
import Typography from '../../typography';
|
|
50
51
|
import useComponent from '../elements';
|
|
51
52
|
import FormContext from '../../form-context';
|
|
52
53
|
import invariant from 'invariant';
|
|
@@ -342,8 +343,21 @@ var Element = function Element(_ref) {
|
|
|
342
343
|
sm: 24,
|
|
343
344
|
xs: 24,
|
|
344
345
|
className: "igloo-element-preview-value",
|
|
345
|
-
children: [error && !!error.length &&
|
|
346
|
-
|
|
346
|
+
children: [error && !!error.length && _jsxs(_Row, {
|
|
347
|
+
style: {
|
|
348
|
+
alignItems: 'center'
|
|
349
|
+
},
|
|
350
|
+
children: [_jsx(_Col, {
|
|
351
|
+
children: _jsx(AlertFilled, {
|
|
352
|
+
className: "igloo-element-preview-value-icon"
|
|
353
|
+
})
|
|
354
|
+
}), _jsx(_Col, {
|
|
355
|
+
children: _jsx(Typography, {
|
|
356
|
+
level: "caption2",
|
|
357
|
+
className: "igloo-element-preview-value-errors",
|
|
358
|
+
children: error.join('\n')
|
|
359
|
+
})
|
|
360
|
+
})]
|
|
347
361
|
}), _jsx("div", {
|
|
348
362
|
children: renderPreviewValue()
|
|
349
363
|
})]
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
color: @error-color;
|
|
26
26
|
margin-right: 8px;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
.igloo-element-preview-value-errors {
|
|
30
|
+
color: @error-color;
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -113,6 +117,10 @@
|
|
|
113
117
|
color: @error-color;
|
|
114
118
|
margin-right: 8px;
|
|
115
119
|
}
|
|
120
|
+
|
|
121
|
+
.igloo-element-preview-value-errors {
|
|
122
|
+
color: @error-color;
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
.ant-form-item-explain-error {
|
package/es/form/hsteps/index.js
CHANGED
|
@@ -32,7 +32,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
32
32
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
33
33
|
import { useState, useContext, useEffect, useReducer, useRef } from 'react';
|
|
34
34
|
import HStep from '../hstep';
|
|
35
|
-
import { calcNamePath } from '../../utils/form-utils';
|
|
35
|
+
import { calcNamePath, getRuleValidation } from '../../utils/form-utils';
|
|
36
36
|
import FormContext from '../../form-context';
|
|
37
37
|
import StepContext from '../../form-step-context';
|
|
38
38
|
import './style/index.less';
|
|
@@ -95,10 +95,12 @@ var HSteps = function HSteps(_ref) {
|
|
|
95
95
|
registerDependencies = _useContext.registerDependencies,
|
|
96
96
|
submitText = _useContext.submitText,
|
|
97
97
|
submitting = _useContext.submitting,
|
|
98
|
-
showSubmitButton = _useContext.showSubmitButton
|
|
98
|
+
showSubmitButton = _useContext.showSubmitButton,
|
|
99
|
+
getRuleValidationApi = _useContext.getRuleValidationApi;
|
|
99
100
|
|
|
100
101
|
var _useContext2 = useContext(LocaleContext),
|
|
101
|
-
formatMessage = _useContext2.formatMessage
|
|
102
|
+
formatMessage = _useContext2.formatMessage,
|
|
103
|
+
currentLang = _useContext2.currentLang;
|
|
102
104
|
|
|
103
105
|
useEffect(function () {
|
|
104
106
|
var subscribe = elements.some(function (_ref2) {
|
|
@@ -117,6 +119,7 @@ var HSteps = function HSteps(_ref) {
|
|
|
117
119
|
}, [currentStep]);
|
|
118
120
|
var renderElements = elements.filter(function (step) {
|
|
119
121
|
invariant(step.type === 'Step', 'Child of steps should be Step');
|
|
122
|
+
invariant(!step.validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
|
|
120
123
|
return typeof step.shouldRender !== 'function' || step.shouldRender(form);
|
|
121
124
|
});
|
|
122
125
|
|
|
@@ -124,14 +127,15 @@ var HSteps = function HSteps(_ref) {
|
|
|
124
127
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
125
128
|
var _allFields$filter;
|
|
126
129
|
|
|
127
|
-
var allFields, _renderElements$curre, currentName, handleNext, namePath, fields, _iterator, _step, collapseSection, errors;
|
|
130
|
+
var allFields, allValues, _renderElements$curre, currentName, handleNext, validationRule, namePath, fields, _iterator, _step, collapseSection, res, errors;
|
|
128
131
|
|
|
129
132
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
130
133
|
while (1) {
|
|
131
134
|
switch (_context.prev = _context.next) {
|
|
132
135
|
case 0:
|
|
133
136
|
allFields = (form === null || form === void 0 ? void 0 : form.getFieldsError()) || [];
|
|
134
|
-
|
|
137
|
+
allValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
|
|
138
|
+
_renderElements$curre = renderElements[current], currentName = _renderElements$curre.name, handleNext = _renderElements$curre.handleNext, validationRule = _renderElements$curre.validationRule;
|
|
135
139
|
namePath = calcNamePath(name, currentName);
|
|
136
140
|
fields = allFields === null || allFields === void 0 ? void 0 : (_allFields$filter = allFields.filter(function (_ref4) {
|
|
137
141
|
var name = _ref4.name;
|
|
@@ -140,17 +144,17 @@ var HSteps = function HSteps(_ref) {
|
|
|
140
144
|
var name = _ref5.name;
|
|
141
145
|
return name;
|
|
142
146
|
});
|
|
143
|
-
_context.prev =
|
|
144
|
-
_context.next =
|
|
147
|
+
_context.prev = 5;
|
|
148
|
+
_context.next = 8;
|
|
145
149
|
return form === null || form === void 0 ? void 0 : form.validateFields(fields);
|
|
146
150
|
|
|
147
|
-
case
|
|
148
|
-
_context.next =
|
|
151
|
+
case 8:
|
|
152
|
+
_context.next = 16;
|
|
149
153
|
break;
|
|
150
154
|
|
|
151
|
-
case
|
|
152
|
-
_context.prev =
|
|
153
|
-
_context.t0 = _context["catch"](
|
|
155
|
+
case 10:
|
|
156
|
+
_context.prev = 10;
|
|
157
|
+
_context.t0 = _context["catch"](5);
|
|
154
158
|
form === null || form === void 0 ? void 0 : form.scrollToField(_context.t0.errorFields[0].name);
|
|
155
159
|
_iterator = _createForOfIteratorHelper(sections.current.values());
|
|
156
160
|
|
|
@@ -167,46 +171,77 @@ var HSteps = function HSteps(_ref) {
|
|
|
167
171
|
|
|
168
172
|
return _context.abrupt("return");
|
|
169
173
|
|
|
170
|
-
case
|
|
174
|
+
case 16:
|
|
175
|
+
if (!(validationRule && getRuleValidationApi)) {
|
|
176
|
+
_context.next = 30;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_context.prev = 17;
|
|
181
|
+
_context.next = 20;
|
|
182
|
+
return getRuleValidation(getRuleValidationApi, validationRule, allValues, currentLang);
|
|
183
|
+
|
|
184
|
+
case 20:
|
|
185
|
+
res = _context.sent;
|
|
186
|
+
|
|
187
|
+
if (!(Array.isArray(res) && res.length)) {
|
|
188
|
+
_context.next = 25;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
form === null || form === void 0 ? void 0 : form.setFields(res);
|
|
193
|
+
form === null || form === void 0 ? void 0 : form.scrollToField(res[0].name);
|
|
194
|
+
return _context.abrupt("return");
|
|
195
|
+
|
|
196
|
+
case 25:
|
|
197
|
+
_context.next = 30;
|
|
198
|
+
break;
|
|
199
|
+
|
|
200
|
+
case 27:
|
|
201
|
+
_context.prev = 27;
|
|
202
|
+
_context.t1 = _context["catch"](17);
|
|
203
|
+
return _context.abrupt("return");
|
|
204
|
+
|
|
205
|
+
case 30:
|
|
171
206
|
if (!(typeof handleNext === 'function')) {
|
|
172
|
-
_context.next =
|
|
207
|
+
_context.next = 42;
|
|
173
208
|
break;
|
|
174
209
|
}
|
|
175
210
|
|
|
176
|
-
_context.prev =
|
|
177
|
-
_context.next =
|
|
211
|
+
_context.prev = 31;
|
|
212
|
+
_context.next = 34;
|
|
178
213
|
return handleNext(form === null || form === void 0 ? void 0 : form.getFieldsValue(fields));
|
|
179
214
|
|
|
180
|
-
case
|
|
215
|
+
case 34:
|
|
181
216
|
errors = _context.sent;
|
|
182
217
|
|
|
183
218
|
if (!Array.isArray(errors)) {
|
|
184
|
-
_context.next =
|
|
219
|
+
_context.next = 37;
|
|
185
220
|
break;
|
|
186
221
|
}
|
|
187
222
|
|
|
188
223
|
return _context.abrupt("return", form === null || form === void 0 ? void 0 : form.setFields(errors));
|
|
189
224
|
|
|
190
|
-
case
|
|
191
|
-
_context.next =
|
|
225
|
+
case 37:
|
|
226
|
+
_context.next = 42;
|
|
192
227
|
break;
|
|
193
228
|
|
|
194
|
-
case
|
|
195
|
-
_context.prev =
|
|
196
|
-
_context.
|
|
229
|
+
case 39:
|
|
230
|
+
_context.prev = 39;
|
|
231
|
+
_context.t2 = _context["catch"](31);
|
|
197
232
|
return _context.abrupt("return");
|
|
198
233
|
|
|
199
|
-
case
|
|
234
|
+
case 42:
|
|
200
235
|
setCurrent(last || current + 1);
|
|
201
236
|
setLast(0);
|
|
202
237
|
setShouldScroll(true);
|
|
203
238
|
|
|
204
|
-
case
|
|
239
|
+
case 45:
|
|
205
240
|
case "end":
|
|
206
241
|
return _context.stop();
|
|
207
242
|
}
|
|
208
243
|
}
|
|
209
|
-
}, _callee, null, [[
|
|
244
|
+
}, _callee, null, [[5, 10], [17, 27], [31, 39]]);
|
|
210
245
|
}));
|
|
211
246
|
|
|
212
247
|
return function handleNext() {
|
package/es/form/index.js
CHANGED
|
@@ -29,7 +29,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
29
29
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
30
30
|
|
|
31
31
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
|
-
import { useState, useImperativeHandle, forwardRef, useRef } from 'react';
|
|
32
|
+
import { useState, useImperativeHandle, forwardRef, useRef, useContext } from 'react';
|
|
33
33
|
import Pages from './pages';
|
|
34
34
|
import Page from './page';
|
|
35
35
|
import Steps from './steps';
|
|
@@ -40,6 +40,8 @@ import messages from './messages';
|
|
|
40
40
|
import './style/index.less';
|
|
41
41
|
import classNames from 'classnames';
|
|
42
42
|
import invariant from 'invariant';
|
|
43
|
+
import { LocaleContext } from '../locale';
|
|
44
|
+
import { getRuleValidation } from './../utils/form-utils';
|
|
43
45
|
|
|
44
46
|
var IglooForm = function IglooForm(props, ref) {
|
|
45
47
|
var config = props.config,
|
|
@@ -63,6 +65,7 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
63
65
|
onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
|
|
64
66
|
uploadApi = props.uploadApi,
|
|
65
67
|
selectDatasourceApi = props.selectDatasourceApi,
|
|
68
|
+
getRuleValidationApi = props.getRuleValidationApi,
|
|
66
69
|
_props$stepDirection = props.stepDirection,
|
|
67
70
|
stepDirection = _props$stepDirection === void 0 ? 'vertical' : _props$stepDirection;
|
|
68
71
|
|
|
@@ -88,31 +91,69 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
88
91
|
firstModifiedCalled = _useState6[0],
|
|
89
92
|
callFirstModified = _useState6[1];
|
|
90
93
|
|
|
94
|
+
var _useContext = useContext(LocaleContext),
|
|
95
|
+
currentLang = _useContext.currentLang;
|
|
96
|
+
|
|
97
|
+
var validationRule = props.validationRule || config.validationRule;
|
|
91
98
|
invariant(type, "Contianer type should be one of ['Pages', 'Page', 'Steps', 'Login']");
|
|
99
|
+
invariant(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
|
|
92
100
|
|
|
93
101
|
var validateMessages = localesProp.validateMessages,
|
|
94
102
|
locales = _objectWithoutProperties(localesProp, _excluded);
|
|
95
103
|
|
|
96
104
|
var handleSubmit = /*#__PURE__*/function () {
|
|
97
105
|
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(values) {
|
|
98
|
-
var allValues, errors;
|
|
106
|
+
var allValues, res, errors;
|
|
99
107
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
100
108
|
while (1) {
|
|
101
109
|
switch (_context.prev = _context.next) {
|
|
102
110
|
case 0:
|
|
103
111
|
allValues = form.getFieldsValue(true);
|
|
112
|
+
setSubmitting(true);
|
|
104
113
|
|
|
105
|
-
if (!(
|
|
106
|
-
_context.next =
|
|
114
|
+
if (!(validationRule && getRuleValidationApi)) {
|
|
115
|
+
_context.next = 18;
|
|
107
116
|
break;
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
setSubmitting(true);
|
|
111
119
|
_context.prev = 3;
|
|
112
120
|
_context.next = 6;
|
|
113
|
-
return
|
|
121
|
+
return getRuleValidation(getRuleValidationApi, validationRule, allValues, currentLang);
|
|
114
122
|
|
|
115
123
|
case 6:
|
|
124
|
+
res = _context.sent;
|
|
125
|
+
|
|
126
|
+
if (!(Array.isArray(res) && res.length)) {
|
|
127
|
+
_context.next = 12;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
form.setFields(res);
|
|
132
|
+
form.scrollToField(res[0].name);
|
|
133
|
+
setSubmitting(false);
|
|
134
|
+
return _context.abrupt("return");
|
|
135
|
+
|
|
136
|
+
case 12:
|
|
137
|
+
_context.next = 18;
|
|
138
|
+
break;
|
|
139
|
+
|
|
140
|
+
case 14:
|
|
141
|
+
_context.prev = 14;
|
|
142
|
+
_context.t0 = _context["catch"](3);
|
|
143
|
+
setSubmitting(false);
|
|
144
|
+
return _context.abrupt("return");
|
|
145
|
+
|
|
146
|
+
case 18:
|
|
147
|
+
if (!(typeof onSubmit === 'function')) {
|
|
148
|
+
_context.next = 27;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_context.prev = 19;
|
|
153
|
+
_context.next = 22;
|
|
154
|
+
return onSubmit(values, allValues);
|
|
155
|
+
|
|
156
|
+
case 22:
|
|
116
157
|
errors = _context.sent;
|
|
117
158
|
|
|
118
159
|
if (Array.isArray(errors)) {
|
|
@@ -120,17 +161,20 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
120
161
|
form.scrollToField(errors[0].name);
|
|
121
162
|
}
|
|
122
163
|
|
|
123
|
-
case
|
|
124
|
-
_context.prev =
|
|
164
|
+
case 24:
|
|
165
|
+
_context.prev = 24;
|
|
166
|
+
setSubmitting(false);
|
|
167
|
+
return _context.finish(24);
|
|
168
|
+
|
|
169
|
+
case 27:
|
|
125
170
|
setSubmitting(false);
|
|
126
|
-
return _context.finish(8);
|
|
127
171
|
|
|
128
|
-
case
|
|
172
|
+
case 28:
|
|
129
173
|
case "end":
|
|
130
174
|
return _context.stop();
|
|
131
175
|
}
|
|
132
176
|
}
|
|
133
|
-
}, _callee, null, [[3,,
|
|
177
|
+
}, _callee, null, [[3, 14], [19,, 24, 27]]);
|
|
134
178
|
}));
|
|
135
179
|
|
|
136
180
|
return function handleSubmit(_x) {
|
|
@@ -233,6 +277,7 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
233
277
|
registerDependencies: registerDependencies,
|
|
234
278
|
uploadApi: uploadApi,
|
|
235
279
|
selectDatasourceApi: selectDatasourceApi,
|
|
280
|
+
getRuleValidationApi: getRuleValidationApi,
|
|
236
281
|
handleValuesChange: handleValuesChange
|
|
237
282
|
}, locales),
|
|
238
283
|
children: _jsxs(_Form, {
|
package/es/form/steps/index.js
CHANGED
|
@@ -19,9 +19,10 @@ import { useState, useContext, useEffect, useReducer, useRef } from 'react';
|
|
|
19
19
|
import invariant from 'invariant';
|
|
20
20
|
import classnames from 'classnames';
|
|
21
21
|
import Step from '../step';
|
|
22
|
-
import { calcNamePath } from '../../utils/form-utils';
|
|
22
|
+
import { calcNamePath, getRuleValidation } from '../../utils/form-utils';
|
|
23
23
|
import FormContext from '../../form-context';
|
|
24
24
|
import StepContext from '../../form-step-context';
|
|
25
|
+
import { LocaleContext } from '../../locale';
|
|
25
26
|
import './style/index.less';
|
|
26
27
|
|
|
27
28
|
var Steps = function Steps(_ref) {
|
|
@@ -64,8 +65,12 @@ var Steps = function Steps(_ref) {
|
|
|
64
65
|
|
|
65
66
|
var _useContext = useContext(FormContext),
|
|
66
67
|
form = _useContext.form,
|
|
68
|
+
getRuleValidationApi = _useContext.getRuleValidationApi,
|
|
67
69
|
registerDependencies = _useContext.registerDependencies;
|
|
68
70
|
|
|
71
|
+
var _useContext2 = useContext(LocaleContext),
|
|
72
|
+
currentLang = _useContext2.currentLang;
|
|
73
|
+
|
|
69
74
|
useEffect(function () {
|
|
70
75
|
var subscribe = elements.some(function (_ref2) {
|
|
71
76
|
var shouldRender = _ref2.shouldRender,
|
|
@@ -89,14 +94,15 @@ var Steps = function Steps(_ref) {
|
|
|
89
94
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
90
95
|
var _allFields$filter;
|
|
91
96
|
|
|
92
|
-
var allFields, _renderElements$curre, currentName, handleNext, namePath, fields, errors;
|
|
97
|
+
var allFields, allValues, _renderElements$curre, currentName, handleNext, validationRule, namePath, fields, res, errors;
|
|
93
98
|
|
|
94
99
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
95
100
|
while (1) {
|
|
96
101
|
switch (_context.prev = _context.next) {
|
|
97
102
|
case 0:
|
|
98
103
|
allFields = (form === null || form === void 0 ? void 0 : form.getFieldsError()) || [];
|
|
99
|
-
|
|
104
|
+
allValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
|
|
105
|
+
_renderElements$curre = renderElements[current], currentName = _renderElements$curre.name, handleNext = _renderElements$curre.handleNext, validationRule = _renderElements$curre.validationRule;
|
|
100
106
|
namePath = calcNamePath(name, currentName);
|
|
101
107
|
fields = allFields === null || allFields === void 0 ? void 0 : (_allFields$filter = allFields.filter(function (_ref4) {
|
|
102
108
|
var name = _ref4.name;
|
|
@@ -105,60 +111,91 @@ var Steps = function Steps(_ref) {
|
|
|
105
111
|
var name = _ref5.name;
|
|
106
112
|
return name;
|
|
107
113
|
});
|
|
108
|
-
_context.prev =
|
|
109
|
-
_context.next =
|
|
114
|
+
_context.prev = 5;
|
|
115
|
+
_context.next = 8;
|
|
110
116
|
return form === null || form === void 0 ? void 0 : form.validateFields(fields);
|
|
111
117
|
|
|
112
|
-
case
|
|
113
|
-
_context.next =
|
|
118
|
+
case 8:
|
|
119
|
+
_context.next = 14;
|
|
114
120
|
break;
|
|
115
121
|
|
|
116
|
-
case
|
|
117
|
-
_context.prev =
|
|
118
|
-
_context.t0 = _context["catch"](
|
|
122
|
+
case 10:
|
|
123
|
+
_context.prev = 10;
|
|
124
|
+
_context.t0 = _context["catch"](5);
|
|
119
125
|
form === null || form === void 0 ? void 0 : form.scrollToField(_context.t0.errorFields[0].name);
|
|
120
126
|
return _context.abrupt("return");
|
|
121
127
|
|
|
122
|
-
case
|
|
128
|
+
case 14:
|
|
129
|
+
if (!(validationRule && getRuleValidationApi)) {
|
|
130
|
+
_context.next = 28;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_context.prev = 15;
|
|
135
|
+
_context.next = 18;
|
|
136
|
+
return getRuleValidation(getRuleValidationApi, validationRule, allValues, currentLang);
|
|
137
|
+
|
|
138
|
+
case 18:
|
|
139
|
+
res = _context.sent;
|
|
140
|
+
|
|
141
|
+
if (!(Array.isArray(res) && res.length)) {
|
|
142
|
+
_context.next = 23;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
form === null || form === void 0 ? void 0 : form.setFields(res);
|
|
147
|
+
form === null || form === void 0 ? void 0 : form.scrollToField(res[0].name);
|
|
148
|
+
return _context.abrupt("return");
|
|
149
|
+
|
|
150
|
+
case 23:
|
|
151
|
+
_context.next = 28;
|
|
152
|
+
break;
|
|
153
|
+
|
|
154
|
+
case 25:
|
|
155
|
+
_context.prev = 25;
|
|
156
|
+
_context.t1 = _context["catch"](15);
|
|
157
|
+
return _context.abrupt("return");
|
|
158
|
+
|
|
159
|
+
case 28:
|
|
123
160
|
if (!(typeof handleNext === 'function')) {
|
|
124
|
-
_context.next =
|
|
161
|
+
_context.next = 40;
|
|
125
162
|
break;
|
|
126
163
|
}
|
|
127
164
|
|
|
128
|
-
_context.prev =
|
|
129
|
-
_context.next =
|
|
165
|
+
_context.prev = 29;
|
|
166
|
+
_context.next = 32;
|
|
130
167
|
return handleNext(form === null || form === void 0 ? void 0 : form.getFieldsValue(fields));
|
|
131
168
|
|
|
132
|
-
case
|
|
169
|
+
case 32:
|
|
133
170
|
errors = _context.sent;
|
|
134
171
|
|
|
135
172
|
if (!Array.isArray(errors)) {
|
|
136
|
-
_context.next =
|
|
173
|
+
_context.next = 35;
|
|
137
174
|
break;
|
|
138
175
|
}
|
|
139
176
|
|
|
140
177
|
return _context.abrupt("return", form === null || form === void 0 ? void 0 : form.setFields(errors));
|
|
141
178
|
|
|
142
|
-
case
|
|
143
|
-
_context.next =
|
|
179
|
+
case 35:
|
|
180
|
+
_context.next = 40;
|
|
144
181
|
break;
|
|
145
182
|
|
|
146
|
-
case
|
|
147
|
-
_context.prev =
|
|
148
|
-
_context.
|
|
183
|
+
case 37:
|
|
184
|
+
_context.prev = 37;
|
|
185
|
+
_context.t2 = _context["catch"](29);
|
|
149
186
|
return _context.abrupt("return");
|
|
150
187
|
|
|
151
|
-
case
|
|
188
|
+
case 40:
|
|
152
189
|
setCurrent(last || current + 1);
|
|
153
190
|
setLast(0);
|
|
154
191
|
setShouldScroll(true);
|
|
155
192
|
|
|
156
|
-
case
|
|
193
|
+
case 43:
|
|
157
194
|
case "end":
|
|
158
195
|
return _context.stop();
|
|
159
196
|
}
|
|
160
197
|
}
|
|
161
|
-
}, _callee, null, [[
|
|
198
|
+
}, _callee, null, [[5, 10], [15, 25], [29, 37]]);
|
|
162
199
|
}));
|
|
163
200
|
|
|
164
201
|
return function handleNext() {
|
|
@@ -183,6 +220,7 @@ var Steps = function Steps(_ref) {
|
|
|
183
220
|
className: 'igloo-steps-content',
|
|
184
221
|
children: renderElements.map(function (child, index) {
|
|
185
222
|
invariant(child.type === 'Step', 'Child of steps should be Step');
|
|
223
|
+
invariant(!child.validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
|
|
186
224
|
return _jsx(StepContext.Provider, {
|
|
187
225
|
value: {
|
|
188
226
|
registerSection: registerSection
|
package/es/form-context.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ declare const _default: React.Context<{
|
|
|
17
17
|
registerDependencies: (name: FormItemName | FormItemName[], updater: Function) => void;
|
|
18
18
|
uploadApi?: string | undefined;
|
|
19
19
|
selectDatasourceApi?: string | undefined;
|
|
20
|
+
getRuleValidationApi?: string | undefined;
|
|
20
21
|
handleValuesChange(changedFields: any): any;
|
|
21
22
|
}>;
|
|
22
23
|
export default _default;
|
|
@@ -46,6 +46,7 @@ import { useContext, useEffect, useRef, useReducer, isValidElement, cloneElement
|
|
|
46
46
|
import { AlertFilled } from 'iglooicon';
|
|
47
47
|
import { calcFormItemProps } from '../../utils/form-utils';
|
|
48
48
|
import FormContext from '../../form-context';
|
|
49
|
+
import Typography from '../../typography';
|
|
49
50
|
import omit from 'omit.js';
|
|
50
51
|
import classNames from 'classnames';
|
|
51
52
|
import './style/index.less';
|
|
@@ -271,8 +272,21 @@ var Element = function Element(props) {
|
|
|
271
272
|
sm: 24,
|
|
272
273
|
xs: 24,
|
|
273
274
|
className: "igloo-freeform-element-preview-value",
|
|
274
|
-
children: [error && !!error.length &&
|
|
275
|
-
|
|
275
|
+
children: [error && !!error.length && _jsxs(_Row, {
|
|
276
|
+
style: {
|
|
277
|
+
alignItems: 'center'
|
|
278
|
+
},
|
|
279
|
+
children: [_jsx(_Col, {
|
|
280
|
+
children: _jsx(AlertFilled, {
|
|
281
|
+
className: "igloo-freeform-element-preview-value-icon"
|
|
282
|
+
})
|
|
283
|
+
}), _jsx(_Col, {
|
|
284
|
+
children: _jsx(Typography, {
|
|
285
|
+
level: "caption2",
|
|
286
|
+
className: "igloo-freeform-element-preview-value-errors",
|
|
287
|
+
children: error.join('\n')
|
|
288
|
+
})
|
|
289
|
+
})]
|
|
276
290
|
}), _jsx("div", {
|
|
277
291
|
children: previewFormater ? previewFormater(value, form) : _typeof(value) === 'object' ? JSON.stringify(value) : value
|
|
278
292
|
})]
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
color: @error-color;
|
|
26
26
|
margin-right: 8px;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
.igloo-freeform-element-preview-value-errors {
|
|
30
|
+
color: @error-color;
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -116,6 +120,10 @@
|
|
|
116
120
|
color: @error-color;
|
|
117
121
|
margin-right: 8px;
|
|
118
122
|
}
|
|
123
|
+
|
|
124
|
+
.igloo-freeform-element-preview-value-errors {
|
|
125
|
+
color: @error-color;
|
|
126
|
+
}
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
.ant-form-item-explain-error {
|