Skip to content

Commit

Permalink
layout keys extra validations
Browse files Browse the repository at this point in the history
* validate key of layoutItem

* Update utils.js
  • Loading branch information
ygj6 authored Jan 20, 2021
1 parent fd0b8c6 commit b42a4c3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ export function synchronizeLayoutWithChildren(initialLayout: Layout, children: A
export function validateLayout(layout: Layout, contextName: string): void {
contextName = contextName || "Layout";
const subProps = ['x', 'y', 'w', 'h'];
let keyArr = [];
if (!Array.isArray(layout)) throw new Error(contextName + " must be an array!");
for (let i = 0, len = layout.length; i < len; i++) {
const item = layout[i];
Expand All @@ -470,11 +471,20 @@ export function validateLayout(layout: Layout, contextName: string): void {
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].' + subProps[j] + ' must be a number!');
}
}
if (item.i && typeof item.i !== 'string') {
// number is also ok, so comment the error
// TODO confirm if commenting the line below doesn't cause unexpected problems
// throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i must be a string!');

if (item.i === undefined || item.i === null) {
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i cannot be null!');
}

if (typeof item.i !== 'number' && typeof item.i !== 'string') {
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i must be a string or number!');
}

if (keyArr.indexOf(item.i) >= 0) {
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].i must be unique!');
}
keyArr.push(item.i);

if (item.static !== undefined && typeof item.static !== 'boolean') {
throw new Error('VueGridLayout: ' + contextName + '[' + i + '].static must be a boolean!');
}
Expand Down

0 comments on commit b42a4c3

Please sign in to comment.