macek/jquery-serialize-object

NPM usage

mb8z opened this issue · 1 comments

mb8z commented

Let's say I have installed this library using the npm method. How am I supposed to used it in my React/ Webpack project?

All I get is that .serializeObject() is not a function

macek commented

You can see how it's used in the tests: where $ is bound to jQuery

An example using the JavaScript API

  it("should return the object", function() {
    var f = new FormSerializer($);
    f.addPair({name: "a[b]", value: "c"});
    f.addPair({name: "a[x]", value: "y"});
    assert.deepEqual(f.serializeJSON(), '{"a":{"b":"c","x":"y"}}');
  });

And an example using the jQuery API

  it("checkbox inputs as booleans if no value is present", function() {
    var $form = $('<form><input type="checkbox" name="a" checked></form>');
    assert.deepEqual($form.serializeObject(), {a: true});
  });

  it("checkbox inputs as strings if other value is present", function() {
    var $form = $('<form><input type="checkbox" name="a" value="b" checked></form>');
    assert.deepEqual($form.serializeObject(), {a: "b"});
  });

  // ...

Does that help?