Skip to content

Commit b42a4c3

Browse files
authored
layout keys extra validations
* validate key of layoutItem * Update utils.js
1 parent fd0b8c6 commit b42a4c3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/helpers/utils.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ export function synchronizeLayoutWithChildren(initialLayout: Layout, children: A
462462
export function validateLayout(layout: Layout, contextName: string): void {
463463
contextName = contextName || "Layout";
464464
const subProps = ['x', 'y', 'w', 'h'];
465+
let keyArr = [];
465466
if (!Array.isArray(layout)) throw new Error(contextName + " must be an array!");
466467
for (let i = 0, len = layout.length; i < len; i++) {
467468
const item = layout[i];
@@ -470,11 +471,20 @@ export function validateLayout(layout: Layout, contextName: string): void {
470471
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].' + subProps[j] + ' must be a number!');
471472
}
472473
}
473-
if (item.i && typeof item.i !== 'string') {
474-
// number is also ok, so comment the error
475-
// TODO confirm if commenting the line below doesn't cause unexpected problems
476-
// throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i must be a string!');
474+
475+
if (item.i === undefined || item.i === null) {
476+
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i cannot be null!');
477+
}
478+
479+
if (typeof item.i !== 'number' && typeof item.i !== 'string') {
480+
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i must be a string or number!');
477481
}
482+
483+
if (keyArr.indexOf(item.i) >= 0) {
484+
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i must be unique!');
485+
}
486+
keyArr.push(item.i);
487+
478488
if (item.static !== undefined && typeof item.static !== 'boolean') {
479489
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].static must be a boolean!');
480490
}

0 commit comments

Comments
 (0)