Bug Tracker

Modify

Ticket #11049 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

submit can not be stopped in ie when bubbling

Reported by: yiminghe Owned by: dmethvin
Priority: high Milestone: None
Component: event Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

  1. input the following html:
<html>
    <head>
    </head>
<body>
<div id='t'>
    <form id='f'>
        <input type='submit' id='s'/>
    </form>
</div>


<script src='jquery-1.7.1.js'></script>

<script>
    $(function(){
        var ret=[];
        
        $("#t").on("submit",function(e){
            e.preventDefault();
            e.stopPropagation();
        });
        
        // trigger jquery's submit hack
        $('#s')[0].click();
        
        setTimeout(function(){        
           $("#t").on("submit",function(e){
                ret.push(1);
                e.preventDefault();
                e.stopPropagation();
            });
            
            $("#f").on("submit",function(e){
                e.preventDefault();
                e.stopPropagation();
            });
            
            $('#s')[0].click();
            
            setTimeout(function(){
                alert(ret.length==0);
            },100);
        },100);
    });
</script>
</body>
</html>
  1. run it in ie

expected : alert(true)

actual result : alert(false)

PS : Maybe event "change" in ie has the same problem,i will check it later. PS2 : I try to fix this bug in KISSY (which learned a lot from jquery),hope it is feasible for jquery too.

  1. place event "submit" fix hander as the last handler always :

 https://github.com/kissyteam/kissy/blob/4bacd0b1364435fd49a6c393a2bcbdf9f560eea3/src/event/submit.js#L47

 https://github.com/kissyteam/kissy/blob/4bacd0b1364435fd49a6c393a2bcbdf9f560eea3/src/event/add.js#L135

  1. do nothing in submit fix handler if user called stopPropagation in his handler:

 https://github.com/kissyteam/kissy/blob/4bacd0b1364435fd49a6c393a2bcbdf9f560eea3/src/event/submit.js#L57

After above fixes the result is fine :

 http://docs.kissyui.com/kissy/src/event/tests/submit-bubble/jq_bug_fix.html

Change History

comment:1 Changed 2 years ago by yiminghe

sorry , open in ie and other browsers :  http://jsfiddle.net/9Ca8C/1/

Version 0, edited 2 years ago by yiminghe (next)

comment:2 Changed 2 years ago by dmethvin

  • Owner set to dmethvin
  • Status changed from new to assigned

Yep, I agree about the bug. Making sure the event runs last will be tricky though, given that other code can attach events later.

comment:3 Changed 2 years ago by yiminghe

yes, it is tricky, especially making sure the submit fix event runs last always even user attach event later , so it need to modify "event add" , and record lastCount ,always place user's event handler before submit fix :

 https://github.com/kissyteam/kissy/blob/4bacd0b1364435fd49a6c393a2bcbdf9f560eea3/src/event/add.js#L135

The above steps fix this bug perfectly, hope you can find a better way

comment:4 Changed 2 years ago by dmethvin

  • Priority changed from undecided to high
  • Component changed from unfiled to event

comment:5 Changed 2 years ago by Dave Methvin

  • Status changed from assigned to closed
  • Resolution set to fixed

Fix #11049. Let bubbling submit be cancellable in oldIE.

Changeset: 92a92be10f2c6eecc93e0def9001a2ef2852fde1

comment:6 Changed 2 years ago by yiminghe

@Dave Methvin

Still not perfect :) , open in ie :  http://jsfiddle.net/yiminghe/v9Zsq/

But i think the current solution is fine in real world.

comment:7 Changed 2 years ago by dmethvin

I agree, any inline handlers may not work properly. We try to make inline handlers work where possible, but they are bad practice and hard to fix since they are outside our event model. Thanks for your help yiminghe!

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.