Skip to content

Commit cc782da

Browse files
authored
Merge pull request #2 from devforth/feature/AdminForth/1704/create-json-editor-plugin
fix: add validation
2 parents 4067303 + d1fbcfa commit cc782da

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

custom/JsonEditor.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ function toObject(): Record<string, any> {
107107
}
108108
109109
function getError(): string | null {
110+
for (const pair of pairs.value) {
111+
const hasKey = !!pair.key.trim();
112+
const hasValue = !!pair.value.trim();
113+
if (!hasKey && !hasValue) {
114+
return 'Empty rows are not allowed';
115+
}
116+
if (!hasKey) {
117+
return 'Value without a key is not allowed';
118+
}
119+
if (!hasValue) {
120+
return 'Key without a value is not allowed';
121+
}
122+
}
110123
const keys = pairs.value.map(p => p.key.trim()).filter(Boolean);
111124
if (new Set(keys).size < keys.length) {
112125
return 'Duplicate keys are not allowed';

0 commit comments

Comments
 (0)