Skip to content

serialize_params Returns Odd Info #595

@JayRennemeyer

Description

@JayRennemeyer

I'm trying to get the ID of a widget container when it gets resized. I added an .attr call to the serialize_params function and it worked for a while. It returned [{"element_id":"admin_stats","col":7,"row":3,"size_x":6,"size_y":4}]. But now it's sending weird data back to the resize.stop function.

Gridster Code:

        var gridster = $('.gridster > .widgetContainer').gridster({
            widget_margins: [10, 10],
            widget_base_dimensions: [100, 60],
            min_cols: 12,
            max_cols: 12,
            resize: {
                enabled: true,
                stop: function(e, ui, $widget) {
                    var widgetInfo = JSON.parse($widget);  // <---Throws error shown below.
                    var newHeight = this.resize_coords.data.height;
                    var newWidth = this.resize_coords.data.width; 
                    $('li#' + widgetInfo.element_id).attr('backgriound-color','red');
                }
            },
            serialize_params: function($w, wgd) {
                return {
                  element_id: $w.attr('id'),
                  col: wgd.col,
                  row: wgd.row,
                  size_x: wgd.size_x,
                  size_y: wgd.size_y,
                };
            }
        }).data('gridster');

The error shown in the console is:
Uncaught SyntaxError: Unexpected token o in JSON at position 1

If I display the results of JSON.stringify($widget), it contains:
{"0":{"jQuery11240030910348659392684":192,"sizzle1505230551480":{"undefined":{"parentNode":[19,14,true]}}},"length":1,"prevObject":{"0":{},"context":{},"length":1},"context":{}}

What is happening and how do I fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions