#7773 closed bug (fixed)
val() documentation contains misleading example
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.5.1 |
Component: | web | Version: | 1.4.4 |
Keywords: | Cc: | kswedberg | |
Blocked by: | Blocking: |
Description
The 2nd example on the documentation page for the setter-version of val() ("Set a single select and a multiple select") contains 4 inputs (2 checkboxes, 2 radio buttons), and some example code that reads
$("input").val(["check1","check2", "radio1" ]);
The effect of that code is to select two of the checkboxes and one of the radio buttons. Of course, if there were a simple text input field on the same page, its content would be set to "check1,check2,radio1", which is stupid. So bad example code for that reason alone.
However, since the only "input" fields on the page are checkboxes or radio buttons, and the example code successfully checks them, it seems reasonable to infer that
$("input:checkbox").val("check1");
would check the first checkbox. It does not. It sets the value of ALL checkboxes to "check1" (which makes sense, syntactically). But the inference would appear reasonable to a newbie.
To further confuse things,
$("input:checkbox").val(["check1"]);
with a single-element list for parameters, does successfully check the first box (and unchecks the 2nd, if it had been checked). Now that just seems weirdly sloppy, since the documentation gives no indication that using a list of parameters somehow behaves differently from a single string parameter.
I just figured this could be cleaned up a bit.
Change History (6)
comment:1 Changed 12 years ago by
Component: | unfiled → attributes |
---|---|
Keywords: | needsdoc added |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 12 years ago by
Cc: | kswedberg added |
---|
comment:3 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | open → closed |
Changed the documentation to more accurately describe the use of an array as .val()'s argument.
comment:4 Changed 12 years ago by
Keywords: | needsdoc removed |
---|
comment:6 Changed 12 years ago by
Component: | attributes → web |
---|---|
Milestone: | 1.6 → 1.5.1 |
@kswedberg i'm pulling you into this just so its on record