PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Checkbox default status=selected...bug?

  1. Ketiga
    Member

    Hi,

    I am experiencing what I think is a bug.

    Since there's no 'select all' functionality for checkboxes yet, I have created two checkbox groups with identical values.
    One group has all the values selected by default.

    I have created a separate checkbox called 'select all'. I hide the unselected group of checkboxes if the 'select all' checkbox is checked in which case I show the group with all values selected by default and vice versa.

    The strange thing is that when I toggle the 'select all' box, the first time it works correctly, all values are checked. The second time around the two last values in the list are NOT checked and the rest of the values in the group are. When I add two more values to the checkbox group, the rest of the values are checked but the two latest added boxes aren't!

    If this is in fact a bug and how do I fix it? I really need this to work.

    Posted 11 years ago on Friday July 27, 2012 | Permalink
  2. Ketiga
    Member

    I can reproduce this issue with second larger group.

    My first example with 20 values did not show the last two values as selected.

    I created a new group with 56 values, which does not show the last FIVE boxes as selected when I select the 'select all' box for the second time...so it seems to increase when you add more values.

    Posted 11 years ago on Friday July 27, 2012 | Permalink
  3. Ketiga
    Member

    Looks like it starts occurring from ten or more checkbox values. When I use nine values it doesn't happen.
    10 values: 1 box loses the checked status
    20 values: 2 boxes lose the checked status
    40 values: 4 boxes lose te checked status
    etc...

    Posted 11 years ago on Friday July 27, 2012 | Permalink
  4. Ketiga
    Member

    Can I get some help please? I am stuck because of this. This concerns an out of the box functionality which I expect to work.

    Posted 11 years ago on Saturday July 28, 2012 | Permalink
  5. Sorry, you caught us outside normal support hours. Can you post a link to your site please where this problem is visible?

    I seem to recall an issue with 9 and 10, 10 being skipped completely (due to sorting, I think, 10 came right after 1 or something.) But I'm not sure if that is related to the issue you have here. We'll have to see it to be able to help you.

    Posted 11 years ago on Sunday July 29, 2012 | Permalink
  6. Ketiga
    Member

    Hi,

    Thank you for your reply.
    I have created a new form to show you the issue (my own form is still in development and has restricted access).

    Please note that I'm not doing anything special (I think).

    I create a list of checkboxes with all values selected by default.
    Next I create a single checbox named 'select all' which is used to show or hide the list of checkboxes using conditional logic.

    To emphasise the issue I have created three lists: the first with 9 values (which always works) and then one with 10 and 20 values. For every ten boxes it shows one box unselected when you toggle the 'select all' checkbox.

    You may have to use the toggle twice because it may work correctly the first time.
    You should be able to recreate a similar form to reproduce the issue.

    Hope this makes sense.

    Thanks for helping!

    Here it is:
    http://ketiga.nl/checkboxes-test/

    Posted 11 years ago on Sunday July 29, 2012 | Permalink
  7. Can you export that form please and email it to me at chris@rocketgenius.com - I would like to install that locally and see how it responds. Thank you

    Posted 11 years ago on Monday July 30, 2012 | Permalink
  8. For reference, this is the issue I was recalling:
    http://www.gravityhelp.com/forums/topic/more-than-10-checkboxes

    Posted 11 years ago on Monday July 30, 2012 | Permalink
  9. Ketiga
    Member

    Thanks, but I don't think this issue is related other than something's going wrong with the tenth checkbox :)

    In my case every tenth checkbox loses its default selected state when used in combination with conditional logic.

    I have e-mailed you my export of the form.

    Thanks for helping out!

    Posted 11 years ago on Monday July 30, 2012 | Permalink
  10. Take a look at this sample form I put up, based on your 20-item list:
    http://gravity.chrishajer.com/select-all-with-jquery/

    I added this HTML block to the form after my list of checkboxes:

    [html]
      <input type="button" class="check" value="Select All" />

    That puts a "Select All" button after the checkbox list.

    Then, I created this script to provide the check/uncheck all functionality:

    [js]
    var $j = jQuery.noConflict();
    $j(document).ready(function(){
        $j('.check:button').toggle(function(){
            $j('input:checkbox').attr('checked','checked');
            $j(this).val('Unselect All')
        },function(){
            $j('input:checkbox').removeAttr('checked');
            $j(this).val('Select All');
        })
    })

    That will toggle back and forth between "Select All" and "Unselect All". I unchecked the boxes in the form builder by default, and have the button saying "Select All".

    I saved that script to a file called "select-all.js" in my child theme's js folder.

    To include that script on the page where this form is in use (form 108), I added this to my theme's functions.php:

    [php]
    add_action('gform_enqueue_scripts_108', 'enqueue_select_all_script', 10, 2);
    function enqueue_select_all_script($form, $is_ajax) {
            wp_enqueue_script('select_all_script', get_stylesheet_directory_uri() . '/js/select-all.js', array('jquery'));
    }

    That will load my script on any page with form 108 present, and handles the jQuery dependency. Change the "108" to your form ID.

    This can be extended if you need, for multiple checkbox lists (right now, it will toggle all check boxes on the form.) You can give a CSS Class name to individual groups of checkboxes if you have more than one group on a form, then add an individual button after each group, and extend the script to target just the specific group of checkboxes you want.

    Let me know if you have any questions with implementation. Thanks.

    Posted 11 years ago on Monday July 30, 2012 | Permalink
  11. Ketiga
    Member

    Hi Chris,

    Thank you. This worked instantly, great!
    Like you mentioned I need a way to select individual groups of checkboxes. Since I am not familiar with jquery (and I have a little trouble understanding the syntax) can you show me how to do this?

    I also still need to be able to use the built in css classes to devide my boxes for instance into 3 or 4 columns.

    Also, once you have used the button to select all the boxes, I need a way to toggle the status of the button back from 'unselect all' to 'select all' once you decide to manually uncheck one of the boxes in the group.

    Thanks a lot so far!

    Posted 11 years ago on Tuesday July 31, 2012 | Permalink
  12. Ketiga
    Member

    Or maybe some hidden value that gets passed only in case all boxes are checked would work as well...I need a way to really tell when all boxes are checked. So when I select all but uncheck a couple of boxes, this value should change.

    Hope this makes sense...

    Posted 11 years ago on Tuesday July 31, 2012 | Permalink
  13. Ketiga
    Member

    While searching Google I found this code:

    http://viralpatel.net/blogs/multiple-checkbox-select-deselect-jquery-tutorial-example/

    This seems to do exactly what I need, but I can't get it to work with Gravity Forms...

    Posted 11 years ago on Tuesday July 31, 2012 | Permalink
  14. Ketiga
    Member

    Ok, I'm not entirely sure why but using your code with the jquery noconflict stuff :)
    I managed to get it working with HTML:

    http://ketiga.nl/checkboxes-test/

    Now I need it to work with form checkboxes instead of a HTML code block.

    Any ideas?

    Posted 11 years ago on Tuesday July 31, 2012 | Permalink
  15. Ketiga
    Member

    Ok, I think I got it working.

    First I created the select all checkbox with an HTML block as you suggested

    <input type="checkbox" id="selectall" value="Select All" />

    Then I used this code in the javascript file
    (change the input numbers so they match your form inputs)

    var $j = jQuery.noConflict();
    
    $j(document).ready(function(){
    
        // add multiple select / deselect functionality
        $j("#selectall").click(function () {
              $j("input[name^='input_3.']").attr('checked', this.checked);
        })
    
        // if all checkbox are selected, check the selectall checkbox
        // and viceversa
        $j("input[name^='input_3.']").click(function(){
    
            if($j("input[name^='input_3.']").length == $j("input[name^='input_3.']:checked").length) {
                $j("#selectall").attr("checked", "checked");
            } else {
                $j("#selectall").removeAttr("checked");
            }
    
        })
    })

    In the theme funtions.php file I only changed my form number.

    Cheers!

    Posted 11 years ago on Thursday August 2, 2012 | Permalink
  16. That sounds pretty good. Is it working for you now?

    Posted 11 years ago on Saturday August 4, 2012 | Permalink
  17. Ketiga
    Member

    yes, it's working for each individual set of checkboxes now as well.

    Posted 11 years ago on Saturday August 4, 2012 | Permalink
  18. Outstanding. I'm glad you were able to make that work Congratulations.

    Posted 11 years ago on Saturday August 4, 2012 | Permalink

This topic has been resolved and has been closed to new replies.