@ramathibodi/nuxt-commons 0.1.47 → 0.1.48
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/module.json
CHANGED
|
@@ -112,13 +112,27 @@ export function escapeObjectForInlineBinding(obj) {
|
|
|
112
112
|
export function buildValidationRules(validationString) {
|
|
113
113
|
validationString = validationString.replace(/^\[|]$/g, "").trim();
|
|
114
114
|
if (!validationRulesRegex.test(validationString)) return "";
|
|
115
|
-
const rules =
|
|
115
|
+
const rules = [];
|
|
116
|
+
let current = "";
|
|
117
|
+
let depth = 0;
|
|
118
|
+
for (let char of validationString) {
|
|
119
|
+
if (char === "," && depth === 0) {
|
|
120
|
+
if (current.trim()) rules.push(current.trim());
|
|
121
|
+
current = "";
|
|
122
|
+
} else {
|
|
123
|
+
if (char === "(") depth++;
|
|
124
|
+
if (char === ")") depth--;
|
|
125
|
+
current += char;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (current.trim()) rules.push(current.trim());
|
|
129
|
+
const formatted = rules.map((rule) => {
|
|
116
130
|
rule = rule.trim();
|
|
117
131
|
if (!rule.startsWith("rules.")) rule = `rules.${rule}`;
|
|
118
132
|
if (!/\(.+\)$/.test(rule)) rule += "()";
|
|
119
133
|
return rule.replace(/"/g, "'");
|
|
120
134
|
});
|
|
121
|
-
return `:rules="[${
|
|
135
|
+
return `:rules="[${formatted.join(",")}]"`;
|
|
122
136
|
}
|
|
123
137
|
export function processDefaultTemplate(item, insideTemplate, optionString, validationRules) {
|
|
124
138
|
if (!validationRules) validationRules = item.validationRules ? buildValidationRules(item.validationRules) || "" : "";
|
|
@@ -5,5 +5,7 @@ import {
|
|
|
5
5
|
} from "./template.js";
|
|
6
6
|
export function processTemplateFormTable(item, parentTemplates) {
|
|
7
7
|
let tableOptions = Object.assign({ title: item.inputLabel || "", formTemplate: "" }, item.inputOptions);
|
|
8
|
-
|
|
8
|
+
let tableHeader = tableOptions.headers || [];
|
|
9
|
+
if (!tableHeader.some((h) => h.key === "action")) tableHeader.push({ title: "Action", key: "action", width: "100px" });
|
|
10
|
+
return processDefaultTemplate(item, `<template #form="{data,rules}">${useDocumentTemplate(tableOptions.formTemplate)}</template>`, `title="${tableOptions.title}" :headers='${escapeObjectForInlineBinding(tableHeader)}'`);
|
|
9
11
|
}
|
|
@@ -7,7 +7,7 @@ export function useRules() {
|
|
|
7
7
|
const requireIf = (conditionIf, customError = "This field is required") => (value) => condition(!!value || value === false || value === 0 || !conditionIf, customError);
|
|
8
8
|
const requireTrue = (customError = "This field must be true") => (value) => condition(!!value, customError);
|
|
9
9
|
const requireTrueIf = (conditionIf, customError = "This field must be true") => (value) => condition(!!value || !conditionIf, customError);
|
|
10
|
-
const numeric = (customError = "This field must be a number") => (value) => condition(!value || !
|
|
10
|
+
const numeric = (customError = "This field must be a number") => (value) => condition(!value || !isNaN(Number(value)), customError);
|
|
11
11
|
const range = (minValue, maxValue, customError = `Value is out of range (${minValue}-${maxValue})`) => (value) => condition(!value || value >= minValue && value <= maxValue, customError);
|
|
12
12
|
const integer = (customError = "This field must be an integer") => (value) => condition(!value || isInteger(value) || /^\+?-?\d+$/.test(value), customError);
|
|
13
13
|
const unique = (data, fieldName, customError = "This field must be unique") => (value) => condition(!value || !data || !find(data, [fieldName, value]), customError);
|