mtoledo87 / dropdown-check-list

Automatically exported from code.google.com/p/dropdown-check-list
0 stars 0 forks source link

When using forceMultiple, a default value is unavoidable #169

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
** What steps will reproduce the problem?

Create a select element without the MULTIPLE attribute.
Add a few options (e.g. Apple, Banana, Orange).
Apply DDCL with forceMultiple set to true.

** What is the expected output? What do you see instead?

I want a checklist with three options (Apple, Banana, Orange), none of which 
are selected by default.

Because an option MUST be selected on a single select element, the first option 
"Apple" is selected even though it does not explicitly carry the SELECTED 
attribute.  With a normal select box, I would add an empty option to the top of 
the list to avoid this problem. If I do that with DDCL, it adds an unwanted 
checkbox for that empty option.

I can see two potential DDCL changes that might allow for this behavior.  
First, you could not create a checkbox for any option with an empty value.  
Second, you could only check the checkboxes for option that explicitly include 
the selected attribute.  If these solutions would cause problems for others, 
perhaps you could implement them as optional features.

** What is your environment?
-- DropDownCheckList version: 1.1
-- jQuery version: 1.4.2
-- jQuery UI version: 1.8.5
-- Browser and version: Chrome 11.0.696.16 beta

Original issue reported on code.google.com by garland....@gmail.com on 24 Mar 2011 at 6:40

GoogleCodeExporter commented 8 years ago
I am using the forceMultiple option because I don't want a tall multiple select 
box to change the page layout until the DDCL is being rendered.  Is this the 
point of the forceMultiple option?  I can style the select box to be one line 
tall, but that makes it very hard to use with js disabled.

Original comment by garland....@gmail.com on 24 Mar 2011 at 6:49

GoogleCodeExporter commented 8 years ago
Here is my workaround for now.

<select name="fruit" id="fruit">
    <option></option>
    <option value="Apple">Apple</option>
    <option value="Banana">Banana</option>
    <option value="Orange">Orange</option>
</select>

$("#fruit").attr('multiple', true);
$("#fruit option:first-child").remove();
$("#fruit").dropdownchecklist();

Instead of using forceMultiple, I add the MULTIPLE attribute, remove the first 
option (the blank one), and then call DDCL.  That happens quickly enough that 
visually you go straight from an empty select element to the empty DDCL.

Original comment by garland....@gmail.com on 24 Mar 2011 at 7:28

GoogleCodeExporter commented 8 years ago
The final issue I encountered with my workaround is that I could not initialize 
multiple options in the select element to be selected (since it's not created 
as a multiple select).  To solve this, I added code to set the initial values 
just before calling DDCL.

$("#fruit").attr('multiple', true);
$("#fruit option:first-child").remove();
$("#fruit").val(["Apple","Orange"]);
$("#fruit").dropdownchecklist();

Original comment by garland....@gmail.com on 24 Mar 2011 at 8:40

GoogleCodeExporter commented 8 years ago
I will add this to the wish-list and see if I can come up with something in a 
future release.

Original comment by womohun...@ittrium.com on 8 Apr 2011 at 5:45

GoogleCodeExporter commented 8 years ago
OOPS - forgot to change issue status to Accepted

Original comment by womohun...@ittrium.com on 8 Apr 2011 at 5:46

GoogleCodeExporter commented 8 years ago
With version 1.4, an empty <Option> can be included as the first element (which 
then gets the auto-default selection)  No checkbox is created for the empty 
option.

Original comment by womohun...@ittrium.com on 14 Jun 2011 at 9:20