Giter Site home page Giter Site logo

jsonforms's Issues

Instead of an empty array, a multiselect control with no selected options submits ['']

If I have a 'select' element in a form with the 'multiple' attribute set, and none of the child options are selected, the resulting json value shows up as an array containing an empty string: ['']

I think the correct value in this situation should be an empty array: []

One possible fix:

Change line 142...

https://github.com/cezary/jquery-html-json-forms/blob/516cf16209eab346a4a0b1147b71fcdc34e477a7/lib/json-forms.js#L142

from

      context = setValue(context, step, currentValue, entry.value, isFile);

to

      if (!(step.type == "array" && entry.value == "")) {
        context = setValue(context, step, currentValue, entry.value, isFile);
      }

Checkbox values are ignored

<input type="checkbox" name="emails[]" value="1" checked />
<input type="checkbox" name="emails[]" value="2" />
<input type="checkbox" name="emails[]" value="3" checked />

For me this should result in this:

{
  "emails": [
    1,
    3
  ]
}

But currently it gets:

{
  "emails": [
    true,
    false,
    true
  ]
}

My workaround is:

<input type="checkbox" name="emailSelected[1]" value="true" checked />
<input type="checkbox" name="emailSelected[2]" value="true" />
<input type="checkbox" name="emailSelected[3]" value="true" checked />

Which results in:

{
  "emailSelected": {
    "1": true,
    "2": false,
    "3": true
  }
}

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.