Skip to content

Commit ecd4c83

Browse files
authored
Updated acceptWidget's documentation (#2028)
* Updated acceptWidget's documentation * Formatting
1 parent b02f9a8 commit ecd4c83

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

doc/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,22 @@ gridstack.js API
6666

6767
## Grid Options
6868

69-
- `acceptWidgets` - accept widgets dragged from other grids or from outside (default: `false`). Can be:
70-
* `true` (uses `'.grid-stack-item'` class filter) or `false`
71-
* string for explicit class name
72-
* `function (i: number, element: Element): boolean` See [example](http://gridstack.github.io/gridstack.js/demo/two.html)
69+
- `acceptWidgets` - Accept widgets dragged from other Gridstack grids or from outside (default: `false`). Can be:
70+
* `true` (The Gridstack grid accepts HTML elements (A Gridstack Grid item is also a HTML element) having `'.grid-stack-item'` as class attribute) or `false`
71+
* Class name. For example, if `acceptWidgets` is set to `'.red-grid-items'`, then the Gridstack grid will only accept HTML elements having `.red-grid-items` as class attribute.
72+
* `function (i: number, element: Element): boolean`. This callback function which is assigned to `acceptWidgets` will be invoked when the user drags an HTML element (A Gridstack Grid item is also a HTML element) on to the Gridstack Grid. For example if `acceptWidgets` is set to
73+
74+
```js
75+
(el) => { const subgridElement = el.getElementsByClassName("grid-stack")
76+
if (subgridElement && subgridElement.length) {
77+
return false;
78+
} else {
79+
return true;
80+
}
81+
}
82+
```
83+
84+
This call back function will be invoked as soon as the user drags an HTML element onto the Gridstack grid, the function parameter `el` will contain the HTML element which was dragged onto the Gridstack Grid. The callback function written above prevents a Gridstack subgrid from being dropped inside of another Gridstack subgrid (Gridstack Grids have class attribute of `.grid-stack`, the callback function in this case makes sure that the HTML element entering the grid doesn't contain any Gridstack grids). See [example](http://gridstack.github.io/gridstack.js/demo/two.html)
7385
- `alwaysShowResizeHandle` - possible values (default: `mobile`) - does not apply to non-resizable widgets
7486
* `false` the resizing handles are only shown while hovering over a widget
7587
* `true` the resizing handles are always shown

0 commit comments

Comments
 (0)