iglooform 2.5.45 → 2.5.46

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/form/index.js CHANGED
@@ -33,6 +33,10 @@ var _classnames = _interopRequireDefault(require("classnames"));
33
33
 
34
34
  var _invariant = _interopRequireDefault(require("invariant"));
35
35
 
36
+ var _locale = require("../locale");
37
+
38
+ var _formUtils = require("./../utils/form-utils");
39
+
36
40
  var _excluded = ["validateMessages"];
37
41
 
38
42
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -85,6 +89,7 @@ var IglooForm = function IglooForm(props, ref) {
85
89
  onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
86
90
  uploadApi = props.uploadApi,
87
91
  selectDatasourceApi = props.selectDatasourceApi,
92
+ getRuleValidationApi = props.getRuleValidationApi,
88
93
  _props$stepDirection = props.stepDirection,
89
94
  stepDirection = _props$stepDirection === void 0 ? 'vertical' : _props$stepDirection;
90
95
 
@@ -110,31 +115,69 @@ var IglooForm = function IglooForm(props, ref) {
110
115
  firstModifiedCalled = _useState6[0],
111
116
  callFirstModified = _useState6[1];
112
117
 
118
+ var _useContext = (0, _react.useContext)(_locale.LocaleContext),
119
+ currentLang = _useContext.currentLang;
120
+
121
+ var validationRule = props.validationRule || config.validationRule;
113
122
  (0, _invariant.default)(type, "Contianer type should be one of ['Pages', 'Page', 'Steps', 'Login']");
123
+ (0, _invariant.default)(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
114
124
 
115
125
  var validateMessages = localesProp.validateMessages,
116
126
  locales = _objectWithoutProperties(localesProp, _excluded);
117
127
 
118
128
  var handleSubmit = /*#__PURE__*/function () {
119
129
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(values) {
120
- var allValues, errors;
130
+ var allValues, res, errors;
121
131
  return regeneratorRuntime.wrap(function _callee$(_context) {
122
132
  while (1) {
123
133
  switch (_context.prev = _context.next) {
124
134
  case 0:
125
135
  allValues = form.getFieldsValue(true);
136
+ setSubmitting(true);
126
137
 
127
- if (!(typeof onSubmit === 'function')) {
128
- _context.next = 11;
138
+ if (!(validationRule && getRuleValidationApi)) {
139
+ _context.next = 18;
129
140
  break;
130
141
  }
131
142
 
132
- setSubmitting(true);
133
143
  _context.prev = 3;
134
144
  _context.next = 6;
135
- return onSubmit(values, allValues);
145
+ return (0, _formUtils.getRuleValidation)(getRuleValidationApi, validationRule, allValues, currentLang);
136
146
 
137
147
  case 6:
148
+ res = _context.sent;
149
+
150
+ if (!(Array.isArray(res) && res.length)) {
151
+ _context.next = 12;
152
+ break;
153
+ }
154
+
155
+ form.setFields(res);
156
+ form.scrollToField(res[0].name);
157
+ setSubmitting(false);
158
+ return _context.abrupt("return");
159
+
160
+ case 12:
161
+ _context.next = 18;
162
+ break;
163
+
164
+ case 14:
165
+ _context.prev = 14;
166
+ _context.t0 = _context["catch"](3);
167
+ setSubmitting(false);
168
+ return _context.abrupt("return");
169
+
170
+ case 18:
171
+ if (!(typeof onSubmit === 'function')) {
172
+ _context.next = 27;
173
+ break;
174
+ }
175
+
176
+ _context.prev = 19;
177
+ _context.next = 22;
178
+ return onSubmit(values, allValues);
179
+
180
+ case 22:
138
181
  errors = _context.sent;
139
182
 
140
183
  if (Array.isArray(errors)) {
@@ -142,17 +185,20 @@ var IglooForm = function IglooForm(props, ref) {
142
185
  form.scrollToField(errors[0].name);
143
186
  }
144
187
 
145
- case 8:
146
- _context.prev = 8;
188
+ case 24:
189
+ _context.prev = 24;
190
+ setSubmitting(false);
191
+ return _context.finish(24);
192
+
193
+ case 27:
147
194
  setSubmitting(false);
148
- return _context.finish(8);
149
195
 
150
- case 11:
196
+ case 28:
151
197
  case "end":
152
198
  return _context.stop();
153
199
  }
154
200
  }
155
- }, _callee, null, [[3,, 8, 11]]);
201
+ }, _callee, null, [[3, 14], [19,, 24, 27]]);
156
202
  }));
157
203
 
158
204
  return function handleSubmit(_x) {
@@ -255,6 +301,7 @@ var IglooForm = function IglooForm(props, ref) {
255
301
  registerDependencies: registerDependencies,
256
302
  uploadApi: uploadApi,
257
303
  selectDatasourceApi: selectDatasourceApi,
304
+ getRuleValidationApi: getRuleValidationApi,
258
305
  handleValuesChange: handleValuesChange
259
306
  }, locales),
260
307
  children: (0, _jsxRuntime.jsxs)(_form.default, {
@@ -21,6 +21,8 @@ var _formContext = _interopRequireDefault(require("../../form-context"));
21
21
 
22
22
  var _formStepContext = _interopRequireDefault(require("../../form-step-context"));
23
23
 
24
+ var _locale = require("../../locale");
25
+
24
26
  require("./style/index.less");
25
27
 
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -81,8 +83,12 @@ var Steps = function Steps(_ref) {
81
83
 
82
84
  var _useContext = (0, _react.useContext)(_formContext.default),
83
85
  form = _useContext.form,
86
+ getRuleValidationApi = _useContext.getRuleValidationApi,
84
87
  registerDependencies = _useContext.registerDependencies;
85
88
 
89
+ var _useContext2 = (0, _react.useContext)(_locale.LocaleContext),
90
+ currentLang = _useContext2.currentLang;
91
+
86
92
  (0, _react.useEffect)(function () {
87
93
  var subscribe = elements.some(function (_ref2) {
88
94
  var shouldRender = _ref2.shouldRender,
@@ -106,14 +112,15 @@ var Steps = function Steps(_ref) {
106
112
  var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
107
113
  var _allFields$filter;
108
114
 
109
- var allFields, _renderElements$curre, currentName, handleNext, namePath, fields, errors;
115
+ var allFields, allValues, _renderElements$curre, currentName, handleNext, validationRule, namePath, fields, res, errors;
110
116
 
111
117
  return regeneratorRuntime.wrap(function _callee$(_context) {
112
118
  while (1) {
113
119
  switch (_context.prev = _context.next) {
114
120
  case 0:
115
121
  allFields = (form === null || form === void 0 ? void 0 : form.getFieldsError()) || [];
116
- _renderElements$curre = renderElements[current], currentName = _renderElements$curre.name, handleNext = _renderElements$curre.handleNext;
122
+ allValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
123
+ _renderElements$curre = renderElements[current], currentName = _renderElements$curre.name, handleNext = _renderElements$curre.handleNext, validationRule = _renderElements$curre.validationRule;
117
124
  namePath = (0, _formUtils.calcNamePath)(name, currentName);
118
125
  fields = allFields === null || allFields === void 0 ? void 0 : (_allFields$filter = allFields.filter(function (_ref4) {
119
126
  var name = _ref4.name;
@@ -122,60 +129,91 @@ var Steps = function Steps(_ref) {
122
129
  var name = _ref5.name;
123
130
  return name;
124
131
  });
125
- _context.prev = 4;
126
- _context.next = 7;
132
+ _context.prev = 5;
133
+ _context.next = 8;
127
134
  return form === null || form === void 0 ? void 0 : form.validateFields(fields);
128
135
 
129
- case 7:
130
- _context.next = 13;
136
+ case 8:
137
+ _context.next = 14;
131
138
  break;
132
139
 
133
- case 9:
134
- _context.prev = 9;
135
- _context.t0 = _context["catch"](4);
140
+ case 10:
141
+ _context.prev = 10;
142
+ _context.t0 = _context["catch"](5);
136
143
  form === null || form === void 0 ? void 0 : form.scrollToField(_context.t0.errorFields[0].name);
137
144
  return _context.abrupt("return");
138
145
 
139
- case 13:
146
+ case 14:
147
+ if (!(validationRule && getRuleValidationApi)) {
148
+ _context.next = 28;
149
+ break;
150
+ }
151
+
152
+ _context.prev = 15;
153
+ _context.next = 18;
154
+ return (0, _formUtils.getRuleValidation)(getRuleValidationApi, validationRule, allValues, currentLang);
155
+
156
+ case 18:
157
+ res = _context.sent;
158
+
159
+ if (!(Array.isArray(res) && res.length)) {
160
+ _context.next = 23;
161
+ break;
162
+ }
163
+
164
+ form === null || form === void 0 ? void 0 : form.setFields(res);
165
+ form === null || form === void 0 ? void 0 : form.scrollToField(res[0].name);
166
+ return _context.abrupt("return");
167
+
168
+ case 23:
169
+ _context.next = 28;
170
+ break;
171
+
172
+ case 25:
173
+ _context.prev = 25;
174
+ _context.t1 = _context["catch"](15);
175
+ return _context.abrupt("return");
176
+
177
+ case 28:
140
178
  if (!(typeof handleNext === 'function')) {
141
- _context.next = 25;
179
+ _context.next = 40;
142
180
  break;
143
181
  }
144
182
 
145
- _context.prev = 14;
146
- _context.next = 17;
183
+ _context.prev = 29;
184
+ _context.next = 32;
147
185
  return handleNext(form === null || form === void 0 ? void 0 : form.getFieldsValue(fields));
148
186
 
149
- case 17:
187
+ case 32:
150
188
  errors = _context.sent;
151
189
 
152
190
  if (!Array.isArray(errors)) {
153
- _context.next = 20;
191
+ _context.next = 35;
154
192
  break;
155
193
  }
156
194
 
157
195
  return _context.abrupt("return", form === null || form === void 0 ? void 0 : form.setFields(errors));
158
196
 
159
- case 20:
160
- _context.next = 25;
197
+ case 35:
198
+ _context.next = 40;
161
199
  break;
162
200
 
163
- case 22:
164
- _context.prev = 22;
165
- _context.t1 = _context["catch"](14);
201
+ case 37:
202
+ _context.prev = 37;
203
+ _context.t2 = _context["catch"](29);
166
204
  return _context.abrupt("return");
167
205
 
168
- case 25:
206
+ case 40:
169
207
  setCurrent(last || current + 1);
170
208
  setLast(0);
171
209
  setShouldScroll(true);
172
210
 
173
- case 28:
211
+ case 43:
174
212
  case "end":
175
213
  return _context.stop();
176
214
  }
177
215
  }
178
- }, _callee, null, [[4, 9], [14, 22]]);
216
+ }, _callee, null, [[5, 10], [15, 25], [29, 37]]);
179
217
  }));
180
218
 
181
219
  return function handleNext() {
@@ -200,6 +238,7 @@ var Steps = function Steps(_ref) {
200
238
  className: 'igloo-steps-content',
201
239
  children: renderElements.map(function (child, index) {
202
240
  (0, _invariant.default)(child.type === 'Step', 'Child of steps should be Step');
241
+ (0, _invariant.default)(!child.validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
203
242
  return (0, _jsxRuntime.jsx)(_formStepContext.default.Provider, {
204
243
  value: {
205
244
  registerSection: registerSection
@@ -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;
@@ -31,6 +31,8 @@ var _formUtils = require("../../utils/form-utils");
31
31
 
32
32
  var _formContext = _interopRequireDefault(require("../../form-context"));
33
33
 
34
+ var _typography = _interopRequireDefault(require("../../typography"));
35
+
34
36
  var _omit = _interopRequireDefault(require("omit.js"));
35
37
 
36
38
  var _classnames = _interopRequireDefault(require("classnames"));
@@ -297,8 +299,21 @@ var Element = function Element(props) {
297
299
  sm: 24,
298
300
  xs: 24,
299
301
  className: "igloo-freeform-element-preview-value",
300
- children: [error && !!error.length && (0, _jsxRuntime.jsx)(_iglooicon.AlertFilled, {
301
- className: "igloo-freeform-element-preview-value-icon"
302
+ children: [error && !!error.length && (0, _jsxRuntime.jsxs)(_row.default, {
303
+ style: {
304
+ alignItems: 'center'
305
+ },
306
+ children: [(0, _jsxRuntime.jsx)(_col.default, {
307
+ children: (0, _jsxRuntime.jsx)(_iglooicon.AlertFilled, {
308
+ className: "igloo-freeform-element-preview-value-icon"
309
+ })
310
+ }), (0, _jsxRuntime.jsx)(_col.default, {
311
+ children: (0, _jsxRuntime.jsx)(_typography.default, {
312
+ level: "caption2",
313
+ className: "igloo-freeform-element-preview-value-errors",
314
+ children: error.join('\n')
315
+ })
316
+ })]
302
317
  }), (0, _jsxRuntime.jsx)("div", {
303
318
  children: previewFormater ? previewFormater(value, form) : _typeof(value) === 'object' ? JSON.stringify(value) : value
304
319
  })]
@@ -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 {
@@ -19,8 +19,14 @@ var _messages = _interopRequireDefault(require("./messages"));
19
19
 
20
20
  require("./style/index.less");
21
21
 
22
+ var _invariant = _interopRequireDefault(require("invariant"));
23
+
22
24
  var _classnames = _interopRequireDefault(require("classnames"));
23
25
 
26
+ var _locale = require("../locale");
27
+
28
+ var _formUtils = require("./../utils/form-utils");
29
+
24
30
  var _excluded = ["validateMessages"];
25
31
 
26
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -72,7 +78,9 @@ var FreeForm = function FreeForm(props) {
72
78
  _props$onFirstModifie = props.onFirstModified,
73
79
  onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
74
80
  uploadApi = props.uploadApi,
75
- selectDatasourceApi = props.selectDatasourceApi;
81
+ selectDatasourceApi = props.selectDatasourceApi,
82
+ validationRule = props.validationRule,
83
+ getRuleValidationApi = props.getRuleValidationApi;
76
84
 
77
85
  var _Form$useForm = _form.default.useForm(),
78
86
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
@@ -94,27 +102,67 @@ var FreeForm = function FreeForm(props) {
94
102
  firstModifiedCalled = _useState6[0],
95
103
  callFirstModified = _useState6[1];
96
104
 
105
+ var _useContext = (0, _react.useContext)(_locale.LocaleContext),
106
+ currentLang = _useContext.currentLang;
107
+
108
+ (0, _invariant.default)(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
109
+
97
110
  var validateMessages = localesProp.validateMessages,
98
111
  locales = _objectWithoutProperties(localesProp, _excluded);
99
112
 
100
113
  var handleSubmit = /*#__PURE__*/function () {
101
114
  var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(values) {
102
- var errors;
115
+ var allValues, res, errors;
103
116
  return regeneratorRuntime.wrap(function _callee$(_context) {
104
117
  while (1) {
105
118
  switch (_context.prev = _context.next) {
106
119
  case 0:
120
+ allValues = form.getFieldsValue(true);
121
+ setSubmitting(true);
122
+
123
+ if (!(validationRule && getRuleValidationApi)) {
124
+ _context.next = 18;
125
+ break;
126
+ }
127
+
128
+ _context.prev = 3;
129
+ _context.next = 6;
130
+ return (0, _formUtils.getRuleValidation)(getRuleValidationApi, validationRule, allValues, currentLang);
131
+
132
+ case 6:
133
+ res = _context.sent;
134
+
135
+ if (!(Array.isArray(res) && res.length)) {
136
+ _context.next = 12;
137
+ break;
138
+ }
139
+
140
+ form.setFields(res);
141
+ form.scrollToField(res[0].name);
142
+ setSubmitting(false);
143
+ return _context.abrupt("return");
144
+
145
+ case 12:
146
+ _context.next = 18;
147
+ break;
148
+
149
+ case 14:
150
+ _context.prev = 14;
151
+ _context.t0 = _context["catch"](3);
152
+ setSubmitting(false);
153
+ return _context.abrupt("return");
154
+
155
+ case 18:
107
156
  if (!(typeof onSubmit === 'function')) {
108
- _context.next = 10;
157
+ _context.next = 27;
109
158
  break;
110
159
  }
111
160
 
112
- setSubmitting(true);
113
- _context.prev = 2;
114
- _context.next = 5;
161
+ _context.prev = 19;
162
+ _context.next = 22;
115
163
  return onSubmit(values);
116
164
 
117
- case 5:
165
+ case 22:
118
166
  errors = _context.sent;
119
167
 
120
168
  if (Array.isArray(errors)) {
@@ -122,17 +170,20 @@ var FreeForm = function FreeForm(props) {
122
170
  form.scrollToField(errors[0].name);
123
171
  }
124
172
 
125
- case 7:
126
- _context.prev = 7;
173
+ case 24:
174
+ _context.prev = 24;
175
+ setSubmitting(false);
176
+ return _context.finish(24);
177
+
178
+ case 27:
127
179
  setSubmitting(false);
128
- return _context.finish(7);
129
180
 
130
- case 10:
181
+ case 28:
131
182
  case "end":
132
183
  return _context.stop();
133
184
  }
134
185
  }
135
- }, _callee, null, [[2,, 7, 10]]);
186
+ }, _callee, null, [[3, 14], [19,, 24, 27]]);
136
187
  }));
137
188
 
138
189
  return function handleSubmit(_x) {
@@ -201,6 +252,7 @@ var FreeForm = function FreeForm(props) {
201
252
  registerDependencies: registerDependencies,
202
253
  uploadApi: uploadApi,
203
254
  selectDatasourceApi: selectDatasourceApi,
255
+ getRuleValidationApi: getRuleValidationApi,
204
256
  handleValuesChange: handleValuesChange
205
257
  }, locales),
206
258
  children: (0, _jsxRuntime.jsx)(_form.default, {
@@ -16,6 +16,7 @@ export interface StepProps extends FormItemConfig {
16
16
  editButtonLabel?: string;
17
17
  disableEditButton?: boolean;
18
18
  buttonText?: string;
19
+ validationRule?: string;
19
20
  }
20
21
  declare const Step: FC<StepProps>;
21
22
  export default Step;
@@ -33,6 +33,8 @@ var _formUtils = require("../../utils/form-utils");
33
33
 
34
34
  var _formContext = _interopRequireDefault(require("../../form-context"));
35
35
 
36
+ var _invariant = _interopRequireDefault(require("invariant"));
37
+
36
38
  require("./style/index.less");
37
39
 
38
40
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -84,10 +86,12 @@ var Step = function Step(_ref) {
84
86
  children = _ref.children,
85
87
  shouldRender = _ref.shouldRender,
86
88
  subscribedFields = _ref.subscribedFields,
87
- buttonText = _ref.buttonText;
89
+ buttonText = _ref.buttonText,
90
+ validationRule = _ref.validationRule;
88
91
 
89
92
  var _useContext = (0, _react.useContext)(_locale.LocaleContext),
90
- formatMessage = _useContext.formatMessage;
93
+ formatMessage = _useContext.formatMessage,
94
+ currentLang = _useContext.currentLang;
91
95
 
92
96
  var _useContext2 = (0, _react.useContext)(_formContext.default),
93
97
  continueText = _useContext2.continueText,
@@ -95,6 +99,7 @@ var Step = function Step(_ref) {
95
99
  submitting = _useContext2.submitting,
96
100
  form = _useContext2.form,
97
101
  showSubmitButton = _useContext2.showSubmitButton,
102
+ getRuleValidationApi = _useContext2.getRuleValidationApi,
98
103
  getScrollContainer = _useContext2.getScrollContainer,
99
104
  registerDependencies = _useContext2.registerDependencies;
100
105
 
@@ -112,6 +117,7 @@ var Step = function Step(_ref) {
112
117
  _ = _useReducer2[0],
113
118
  dispatch = _useReducer2[1];
114
119
 
120
+ (0, _invariant.default)(!validationRule || getRuleValidationApi, 'Please provide getRuleValidationApi in Form props');
115
121
  (0, _react.useEffect)(function () {
116
122
  if (shouldRender || getButtonDisabledState) {
117
123
  registerDependencies(Array.isArray(subscribedFields) ? subscribedFields : 'SUBSCRIBE_ALL', dispatch);
@@ -171,12 +177,13 @@ var Step = function Step(_ref) {
171
177
  var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
172
178
  var _allFields$filter;
173
179
 
174
- var allFields, fields, errors;
180
+ var allFields, allValues, fields, res, errors;
175
181
  return regeneratorRuntime.wrap(function _callee$(_context) {
176
182
  while (1) {
177
183
  switch (_context.prev = _context.next) {
178
184
  case 0:
179
185
  allFields = (form === null || form === void 0 ? void 0 : form.getFieldsError()) || [];
186
+ allValues = form === null || form === void 0 ? void 0 : form.getFieldsValue(true);
180
187
  fields = allFields === null || allFields === void 0 ? void 0 : (_allFields$filter = allFields.filter(function (_ref3) {
181
188
  var name = _ref3.name;
182
189
  return name.join().startsWith(pName === null || pName === void 0 ? void 0 : pName.join());
@@ -184,54 +191,85 @@ var Step = function Step(_ref) {
184
191
  var name = _ref4.name;
185
192
  return name;
186
193
  });
187
- _context.prev = 2;
188
- _context.next = 5;
194
+ _context.prev = 3;
195
+ _context.next = 6;
189
196
  return form === null || form === void 0 ? void 0 : form.validateFields(fields);
190
197
 
191
- case 5:
192
- _context.next = 11;
198
+ case 6:
199
+ _context.next = 12;
193
200
  break;
194
201
 
195
- case 7:
196
- _context.prev = 7;
197
- _context.t0 = _context["catch"](2);
202
+ case 8:
203
+ _context.prev = 8;
204
+ _context.t0 = _context["catch"](3);
198
205
  form === null || form === void 0 ? void 0 : form.scrollToField(_context.t0.errorFields[0].name);
199
206
  return _context.abrupt("return");
200
207
 
201
- case 11:
208
+ case 12:
209
+ if (!(validationRule && getRuleValidationApi)) {
210
+ _context.next = 26;
211
+ break;
212
+ }
213
+
214
+ _context.prev = 13;
215
+ _context.next = 16;
216
+ return (0, _formUtils.getRuleValidation)(getRuleValidationApi, validationRule, allValues, currentLang);
217
+
218
+ case 16:
219
+ res = _context.sent;
220
+
221
+ if (!(Array.isArray(res) && res.length)) {
222
+ _context.next = 21;
223
+ break;
224
+ }
225
+
226
+ form === null || form === void 0 ? void 0 : form.setFields(res);
227
+ form === null || form === void 0 ? void 0 : form.scrollToField(res[0].name);
228
+ return _context.abrupt("return");
229
+
230
+ case 21:
231
+ _context.next = 26;
232
+ break;
233
+
234
+ case 23:
235
+ _context.prev = 23;
236
+ _context.t1 = _context["catch"](13);
237
+ return _context.abrupt("return");
238
+
239
+ case 26:
202
240
  if (!(typeof handleNextProp === 'function')) {
203
- _context.next = 22;
241
+ _context.next = 37;
204
242
  break;
205
243
  }
206
244
 
207
- _context.prev = 12;
208
- _context.next = 15;
245
+ _context.prev = 27;
246
+ _context.next = 30;
209
247
  return handleNextProp(form === null || form === void 0 ? void 0 : form.getFieldsValue(fields));
210
248
 
211
- case 15:
249
+ case 30:
212
250
  errors = _context.sent;
213
251
 
214
252
  if (Array.isArray(errors)) {
215
253
  form === null || form === void 0 ? void 0 : form.setFields(errors);
216
254
  }
217
255
 
218
- _context.next = 22;
256
+ _context.next = 37;
219
257
  break;
220
258
 
221
- case 19:
222
- _context.prev = 19;
223
- _context.t1 = _context["catch"](12);
259
+ case 34:
260
+ _context.prev = 34;
261
+ _context.t2 = _context["catch"](27);
224
262
  return _context.abrupt("return");
225
263
 
226
- case 22:
264
+ case 37:
227
265
  handleNextStep && handleNextStep(fields);
228
266
 
229
- case 23:
267
+ case 38:
230
268
  case "end":
231
269
  return _context.stop();
232
270
  }
233
271
  }
234
- }, _callee, null, [[2, 7], [12, 19]]);
272
+ }, _callee, null, [[3, 8], [13, 23], [27, 34]]);
235
273
  }));
236
274
 
237
275
  return function handleNext() {
package/lib/types.d.ts CHANGED
@@ -28,6 +28,8 @@ export interface FormBasicConfig {
28
28
  onFirstModified?: () => any;
29
29
  uploadApi?: string;
30
30
  selectDatasourceApi?: string;
31
+ validationRule?: string;
32
+ getRuleValidationApi?: string;
31
33
  stepDirection?: 'vertical' | 'horizontal';
32
34
  }
33
35
  export declare type FormItemAssert = {
@@ -120,6 +122,7 @@ export interface FormItemExtraConfig extends FormItemProps {
120
122
  minLength?: number;
121
123
  maxLength?: number;
122
124
  idType?: 'KTP' | 'NIK';
125
+ validationRule?: string;
123
126
  [key: string]: any;
124
127
  }
125
128
  export interface FormItemConfig extends FormItemExtraConfig {
@@ -73,3 +73,4 @@ export declare const calcSelectValue: (selectValue?: FormItemSelectValue[] | und
73
73
  disabled: boolean | undefined;
74
74
  };
75
75
  export declare const calcShouldRender: (dependencies?: NamePath[], asserts?: FormItemAssert[], shouldRender?: ((form?: FormInstance<any> | undefined) => boolean) | undefined, form?: FormInstance<any> | undefined) => boolean;
76
+ export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string | undefined) => Promise<any>;