Coder Social home page Coder Social logo

jonathansp / jquery-serializefields Goto Github PK

View Code? Open in Web Editor NEW
13.0 13.0 4.0 446 KB

jQuery plugin to serialize form elements into a JSON object using fieldsets.

License: GNU General Public License v2.0

HTML 18.06% JavaScript 81.94%
javascript jquery jquery-plugin

jquery-serializefields's People

Contributors

chaparo avatar cristianoliveira avatar dependabot[bot] avatar jonathansp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jquery-serializefields's Issues

Add support to select and multiple select inputs.

Add support to select and multiple select inputs.

Look that test:

QUnit.test("When form has select input it should get value from selected", function(assert) {

    // given
    var form = '<form>'+
    '<select name="carlist">'+
    ' <option value="volvo" selected>Volvo</option>'+
    ' <option value="saab">Saab</option>'+
    ' <option value="opel">Opel</option>'+
    '</select>'+
    '</form>';

    // when
    var result = $(form).serializeFields()

    // then
    assert.equal(result.carlist, "volvo", "Property carlist has value Volvo!")
});

IE 11 support

Not sure if its something to do with my setup, or if there is an actual issue with IE 11 support but..

the serialiserializeFields method gathers all the data into a JSON object, but doesn't group by the fieldset names. All the keys are at the same level.

Anybody had experience with this? Cheers

P.S. a client uses IE not me!

Problem when parse check box.

When parsing checkbox input it get value even if checkbox is not checked. I think the best solution for that case is:

See that test case:

QUnit.test( "When form has checkbox it should get value only from 'checked'", function( assert ) {
  // given
  var form = '<form>'+
             '  <input type="checkbox" name="check1" value="true" checked/>'+
             '  <input type="checkbox" name="check2" value="true"/>'+
             '  <input type="checkbox" name="check3" value="true"/>'+
             '</form>';

  // when
  var result = $(form).serializeFields()

  // then
  assert.equal(result.check1, "true","Property check1 has value!")
  assert.ok(!wasDefined(result.check2),"Property check2 was not defined!")
  assert.ok(!wasDefined(result.check3),"Property check3 was not defined!")
});

Problem when get value from radio input

It get the last value from a Radio input.

Look this test case:

QUnit.test("When form has radio button input it should get value from checked", function(assert) {

    // given
    var form = '<form>'+
    +'<input type="radio" name="sex" value="male" checked>Male'
    +'<input type="radio" name="sex" value="female">Female'
    +'</form>';

    // when
    var result = $(form).serializeFields()

    // then
    assert.equal(result.sex, "male", "Property sex has value male!")
});

Create a way to ignore selected fields.

Create a way to ignore fields by tag like:

    <fieldset name="contact">
        <input type="text" name="email" value="[email protected]" />
        <fieldset name="phones">
            <input type="text" name="primary" value="+55 51 123456789" />
            <input type="text" name="mobile" value="+55 51 987654987" />
            <!-- ignore this field -->
            <input data-ignored-field="true" hidden type="text" name="my_ignored_field" value="nothing" />
        </fieldset>
    </fieldset>

Thxs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.