Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if item type: 'boolean', issue #41

Closed
jupe opened this issue Mar 27, 2013 · 3 comments
Closed

if item type: 'boolean', issue #41

jupe opened this issue Mar 27, 2013 · 3 comments

Comments

@jupe
Copy link

jupe commented Mar 27, 2013

if checkbox is unchecked and press submit button, uncheck state is not regonized at all because of serializeArray() . There is one fix for jquery ( https://github.com/madrobby/zepto/pull/248/commits ), but i think it is not added to main jQuery branch. One possible way to fix this issue is to add concat just after serializeArray() -->

line: 2138
/* Because serializeArray() ignores unset checkboxes and radio buttons: */
formArray = formArray.concat(
$(':input[type=checkbox]:not(:checked)', this.el).map( function() {
return {"name": this.name, "value": this.checked}
}).get()
);

@mkirsten
Copy link

Isn't this how this is handled in pure html forms as well?

@scien
Copy link
Contributor

scien commented May 6, 2013

thanks for the fix jupe. worked great

@tidoust
Copy link
Contributor

tidoust commented Jun 4, 2013

I included the provided patch in 8d3bb01.

I initially did that because I thought that validation would fail if the schema key was defined as required in the schema and the user left the box unchecked. Having checked with a real example, I realized that required has another meaning in Web browsers: a required checkbox must be checked for validation to succeed in a Web browser that supports the required attribute. Since that's not the meaning of the required property in JSON Schema, I disabled the addition of a required attribute to checkbox fields in 4a00a47.

That second change means that there is no way to define a checkbox that users must check before they proceed (a typical example would the infamous "by clicking here, you agree with our terms of service"). I do not know how to express such a flag in JSON Schema though.

@tidoust tidoust closed this as completed Jun 4, 2013
tidoust pushed a commit that referenced this issue Jul 4, 2013
A recent change (#41) sends unchecked checkboxes as falsy values
when the form is submitted (instead of not sending them at all).

However, that change does not take into account the fact that
checkboxes may be in a "disabled" state. A disabled checkbox must
not take part in the construction of the submitted object.

Issues typically rise when a checkbox appears in more than one tabs
of a "selectfieldset". Fields that are in inactive tabs are correctly
flagged as "disabled" but since the code did not check that flag, it
would override a possibly checked value with the falsy value of the
last occurrence of the checkbox in the tabs of the selectfieldset.
Best illustrated with the example JSON Form object below where the
"flag" checkbox appears for Choice 1 and Choice 3:

{
  "schema": {
    "choice": {
      "type": "string",
      "title": "Make a choice",
      "enum": [ "Choice 1", "Choice 2", "Choice 3" ]
    },
    "flag": {
      "type": "boolean",
      "title": "Check me up"
    }
  },
  "form": [
    {
      "type": "selectfieldset",
      "key": "choice",
      "items": [
        flag,
        { "type": "section" },
        flag
      ]
    }
  ]
}

If "Choice 1" was selected and the checkbox checked, "flag" was not
set in the submitted object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants