@flowgram.ai/form 0.1.18 → 0.1.22

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/esm/index.js CHANGED
@@ -203,12 +203,6 @@ var Glob;
203
203
  })(Glob || (Glob = {}));
204
204
 
205
205
  // src/types/validate.ts
206
- function isFieldWarning(f) {
207
- if (f.level === "warning" /* Warning */) {
208
- return true;
209
- }
210
- return false;
211
- }
212
206
  var ValidateTrigger = /* @__PURE__ */ ((ValidateTrigger2) => {
213
207
  ValidateTrigger2["onChange"] = "onChange";
214
208
  ValidateTrigger2["onBlur"] = "onBlur";
@@ -927,21 +921,19 @@ var FieldModel = class {
927
921
  this.form.onValidateEmitter.fire(this.form.state);
928
922
  }
929
923
  async _runAsyncValidate() {
930
- const errors = [];
931
- const warnings = [];
932
- const result = await this.form.validateIn(this.name);
933
- if (!result) {
924
+ let errors = [];
925
+ let warnings = [];
926
+ const results = await this.form.validateIn(this.name);
927
+ if (!results?.length) {
934
928
  return {};
935
929
  } else {
936
- const feedback = toFeedback(result, this.name);
937
- if (!feedback) {
930
+ const feedbacks = results.map((result) => toFeedback(result, this.name)).filter(Boolean);
931
+ if (!feedbacks?.length) {
938
932
  return {};
939
933
  }
940
- if (isFieldWarning(feedback)) {
941
- warnings.push(feedback);
942
- } else {
943
- errors.push(feedback);
944
- }
934
+ const groupedFeedbacks = groupBy(feedbacks, "level");
935
+ warnings = warnings.concat(groupedFeedbacks["warning" /* Warning */]);
936
+ errors = errors.concat(groupedFeedbacks["error" /* Error */]);
945
937
  }
946
938
  return { errors, warnings };
947
939
  }
@@ -1360,10 +1352,10 @@ var FormModel = class {
1360
1352
  if (!this._options.validate) {
1361
1353
  return;
1362
1354
  }
1363
- const validateKey = Object.keys(this._options.validate).find(
1355
+ const validateKeys = Object.keys(this._options.validate).filter(
1364
1356
  (pattern) => Glob.isMatch(pattern, name)
1365
1357
  );
1366
- if (validateKey) {
1358
+ const validatePromises = validateKeys.map(async (validateKey) => {
1367
1359
  const validate = this._options.validate[validateKey];
1368
1360
  return validate({
1369
1361
  value: this.getValueIn(name),
@@ -1371,7 +1363,8 @@ var FormModel = class {
1371
1363
  context: this.context,
1372
1364
  name
1373
1365
  });
1374
- }
1366
+ });
1367
+ return Promise.all(validatePromises);
1375
1368
  }
1376
1369
  async validate() {
1377
1370
  if (!this._options.validate) {