nox-validation 1.2.7 → 1.2.9

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.
Files changed (2) hide show
  1. package/lib/validate.js +14 -2
  2. package/package.json +1 -1
package/lib/validate.js CHANGED
@@ -157,7 +157,7 @@ const isEmptyRelational = ({ api_version, value, interface }) => {
157
157
  return value?.length > 0;
158
158
  }
159
159
  } else {
160
- return value?.create?.length > 0 || value?.existing?.length > 0;
160
+ return value?.create?.length > 0 || value?.existing?.length > 0 || value?.update?.length > 0;
161
161
  }
162
162
  return false;
163
163
  };
@@ -543,10 +543,22 @@ const generateErrorMessage = (
543
543
 
544
544
  const handleRule = (rule, field, value, addError, currentPath, formData, error_messages) => {
545
545
  const ruleValue = rule?.value;
546
- const messageValue = Array.isArray(ruleValue) ? ruleValue.join(", ") : String(ruleValue);
546
+ let messageValue = Array.isArray(ruleValue) ? ruleValue.join(", ") : String(ruleValue);
547
547
  const fieldLabel = formatLabel(field.display_label);
548
548
  const custom_message = rule?.custom_message;
549
549
 
550
+ if (rule.case === constants.rulesTypes.ONE_OF && choices.includes(field?.meta?.interface)) {
551
+ const fieldChoices = field?.meta?.options?.choices || [];
552
+ const ruleValues = Array.isArray(ruleValue) ? ruleValue : [ruleValue];
553
+
554
+ const labelValuePairs = ruleValues.map((val) => {
555
+ const matched = fieldChoices.find((item) => String(item.value) === String(val));
556
+ return matched ? `${matched.label} (${matched.value})` : val;
557
+ });
558
+
559
+ messageValue = labelValuePairs.join(", ");
560
+ }
561
+
550
562
  const addValidationError = (ruleKey, extraValues = {}, custom_message) =>
551
563
  addError(
552
564
  currentPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nox-validation",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "validate dynamic schema",
5
5
  "main": "index.js",
6
6
  "scripts": {