Forum Moderators: open

Message Too Old, No Replies

undoing stopPropagation() and cancelBubble

making a form active again

         

dhiggerdhigger

12:55 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



If a function like this has been called to disable the Submit button in a form (for an AJAX app):

/*
* Kills an event's propagation and default action
*/
function knackerEvent(eventObject) {
if (eventObject && eventObject.stopPropagation) {
eventObject.stopPropagation();
}
if (window.event && window.event.cancelBubble ) {
window.event.cancelBubble = true;
}
if (eventObject && eventObject.preventDefault) {
eventObject.preventDefault();
}
if (window.event) {
window.event.returnValue = false;
}
}

Is it possible to undo all of that, to make the form active again, as it would be after a page-reload? I've tried searching for information on stopPropagation() and cancelBubble. Would
window.event.cancelBubble = false
and
window.event.returnValue = false
work? What about
eventObject.preventDefault()
and
eventObject.stopPropagation()
?

Rambo Tribble

1:47 pm on Feb 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe cancelBubble and stopPropagation work on a single event instance; they are a not a switch that needs to be flipped, but an action that must be removed from the response to the event.

Probably the easiest way to accomplish that is to apply the initial code to the object's event property and then simply reassign it as you wish.

dhiggerdhigger

2:01 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



Thanks for posting. Unfortunately

"then simply reassign it as you wish"

is not simple to me! Would you explain what you mean?

Bernard Marx

9:32 pm on Feb 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you don't have edit access to the function...

remove:
_knackerEvent = knackerEvent;
knackerEvent = function(){return true}

re-apply:
knackerEvent = _knackerEvent;

dhiggerdhigger

10:09 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



Ah I see now what is being suggested. Thanks for the clarification. Disabling the function whilst still returning true (as suggested above) causes the Ajax functionality to break. I will debug that situation if I have to but I'm a bit of a JS noob and don't want to spend days of fumbling in the dark! So before I do that...

Instead of preventing the knackerEvent function, is it possible to undo/repair what it did, after it has executed? Is a counter-function to knackerEvent() possible? Or does RT's post above mean that these commands don't work like that?

dhiggerdhigger

10:14 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



A tiny bit more clarification..

I realise now that the form disabling does not happen with the knackerEvent function - it does something else. The form input disabling happens on lines like this:

     target.getElementsByTagName('select')[0].disabled = true;
target.getElementsByTagName('input')[0].disabled = true;

I think that the knackerEvent function is responsible for disabling the form (even though I can stop the greying-out of the elements. This is why I want to "undo" it, after the Ajax magic has happened.