Bug Tracker

Modify

Ticket #10461 (closed bug: worksforme)

Opened 20 months ago

Last modified 9 months ago

selector :checked sometimes returns object with checked attribute false (Opera only)

Reported by: sea128@… Owned by:
Priority: low Milestone: None
Component: selector Version: 1.6.4
Keywords: Cc:
Blocking: Blocked by:

Description

Tested on Opera 11.51 Windows 7. This works at IE 9 and Firefox 6.0.3 and Firefox 7.0.1 without problems. $("input[name='bar']:checked") sometimes returns object with checked attribute set to false.

Clicking on disallow and allow radios sometimes did not change disable property.

How to reproduce bug: clicking on disallow and allow radios with rate 1 click per second. If disabling and enabling checkbox working then click on "Not interesting" radio (unchecked) and then continue clicking on disallow and allow radios.

How to not reproduce bug: click very slow rate (about 1 click per 10 seconds).

I do not know if this selector is invalid (it works in IE and Firefox) but I know how workaround this problem. Instead of $("input[name='bar']:checked") use $("input[name='bar']").filter(":checked")

Example code:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>
  <script type='text/javascript'>
  //<![CDATA[ 
  $(document).ready(function() {
    function update() {
                var element = $("input[name='bar']:checked");   //BUGGY
                //var element = $("input[name='bar']").filter(":checked");//WORKING
                if (element.length==1&&!element[0].checked) {
                        alert("Error");
                }
        var value = element.val();
        if (value == "disallow") {
            $("#some_checkbox").prop({
                disabled: true
            });
        } else {
            $("#some_checkbox").prop({
                disabled: false
            });
        }
    }
    update();
    $("input[type='radio']").change(function() {
        update();
    });

});
  //]]> 
  </script>
  
</head>
<body>
  <form action="" method="post">
    <div>
        <input type="radio" name="foo" value="foo1" id="foo1" checked="checked"><label for="foo1">Not interesting 1</label><br> 
        <input type="radio" name="foo" value="foo2" id="foo2"><label for="foo2">Not interesting 2</label><br> 
        <input type="radio" name="bar" value="disallow" id="disallow" checked="checked"><label for="disallow">Disallow checkbox</label><br>
        <input type="radio" name="bar" value="allow" id="allow"><label for="allow">Allow checkbox</label><br> 
        <input type="checkbox" id="some_checkbox" name="some_checkbox"><label for="some_checkbox">some checkbox</label>
    </div>
</form>
</body>
</html>

Change History

comment:1 Changed 20 months ago by timmywil

  • Priority changed from undecided to low
  • Resolution set to worksforme
  • Status changed from new to closed
  • Component changed from unfiled to selector

Works for me in Opera 11.51.

 http://jsfiddle.net/timmywil/MWmBR/1/

comment:2 Changed 9 months ago by lexx918@…

Hey. I have the same problem. But I found another solution to it! Compare my two versions:  http://jsfiddle.net/Lexx918/yzVfc/ (works!)  http://jsfiddle.net/Lexx918/yzVfc/1/ (does not work) Different one (well, two) lines.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.