ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.04k stars 1.2k forks source link

On serialize(): Uncaught TypeError: Cannot read property 'width' of undefined #447

Open dustinbolton opened 9 years ago

dustinbolton commented 9 years ago

Calling gridster.serialize() after adding a widget via add_widget() results in the error:

Uncaught TypeError: Cannot read property 'width' of undefined in jquery-1.20.2.js:7237

Which is "val = elem.style[ name ];" in the getWidthOrHeight() method.

The HTML added by add_widget() appear accurate and the board functions fine other than adding a widget causing serialize capabilities to fail.

Any ideas on how to troubleshoot this further?

Daijobou commented 9 years ago

First step: add a jsfiddle link to your problem. So every can see this is a bug and not wrong code of yours.

dustinbolton commented 9 years ago

I discovered the problem was indeed mine. My HTML passed to add_widget() included a

at the same level of the
  • . I'm not sure if this is a bug or expected behavior. It's simple enough to fix, just difficult to hunt down. :)

    For anyone else that encounters this issue, this is an example of HTML passed into the first parameter of add_widget() that causes this issue (note the div at the bottom):

    <li class="gs-w" data-id="abcdefg" data-row="1" data-col="1" data-sizex="1" data-sizey="">
        <div class="widget-head">
            <div class="widget-title">Title</div>
        </div>
        <div class="widget-content">
            My content.
        </div>
    </li>
    <div>this causes problems</div>
  • rinkurajat commented 9 years ago

    Gridster is based on unordered HTML tag format is "

    • ....
    " Yo cannot have a DIV tag after LI until you come out of UL tagin between. Based on th HTML submitted by you the HTMl for gridster would look like

    • Title
      My content.
    • this causes problems
    • Title
      My content.
    • this causes problems
      ....