Skip to content

Commit dd4463a

Browse files
committed
add support for uniqueItems #49
1 parent 43957cb commit dd4463a

File tree

3 files changed

+1345
-1327
lines changed

3 files changed

+1345
-1327
lines changed

dist/js/brutusin-json-forms.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ if (typeof brutusin === "undefined") {
7575
"maximum": "Value must be **lower or equal than** `{0}`",
7676
"exclusiveMaximum": "Value must be **lower than** `{0}`",
7777
"minProperties": "At least `{0}` properties are required",
78-
"maxProperties": "At most `{0}` properties are allowed"
79-
78+
"maxProperties": "At most `{0}` properties are allowed",
79+
"uniqueItems": "Array items must be unique"
8080
};
8181

8282
/**
@@ -699,6 +699,15 @@ if (typeof brutusin === "undefined") {
699699
if (s.maxItems && s.maxItems < table.rows.length) {
700700
return BrutusinForms.messages["maxItems"].format(s.maxItems);
701701
}
702+
if (s.uniqueItems) {
703+
for (var i = 0; i < current.length; i++) {
704+
for (var j = i + 1; j < current.length; j++) {
705+
if (JSON.stringify(current[i]) === JSON.stringify(current[j])) {
706+
return BrutusinForms.messages["uniqueItems"];
707+
}
708+
}
709+
}
710+
}
702711
};
703712
addButton.onclick = function () {
704713
addItem(current, table, id + "[#]", null);

0 commit comments

Comments
 (0)