[jQuery] Chaining event handlers
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=570455300-03082006><FONT color=#000080
size=2>i don't find it sloppy at all since event bubbling works in the same
fashion. an event queue is superior to hard coding specific sequences
since it allows flexibility. with the isValid() { ajax stuff } approach,
that piece of code has to be manually written into any page that needs the
behavior. with a queue, simply add ValidateForm(evt) then
AjaxSubmit(evt) to the form's submit queue. this approach is clean,
unobtrusive, and easily allows multiple actions without requiring page specific
code to script the actions.</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> discuss-bounces@jquery.com
[mailto:discuss-bounces@jquery.com] <B>On Behalf Of </B>Blair
McKenzie<BR><B>Sent:</B> Wednesday, August 02, 2006 8:50 PM<BR><B>To:</B> jQuery
Discussion.<BR><B>Subject:</B> Re: [jQuery] Chaining event
handlers<BR></FONT><BR></DIV>
<DIV></DIV>Relying on event queues to behave that way is a bit sloppy. If the
AJAX stuff is only supposed to happen after successfull validation then you
should just use a if (isValid(yourform)) { ajax stuff }.<BR><BR>Blair<BR><BR>
<DIV><SPAN class=gmail_quote>On 8/3/06, <B class=gmail_sendername>Antonio
Collins</B> <<A
href="mailto:Antonio.Collins@d3methods.com">Antonio.Collins@d3methods.com</A>>
wrote:</SPAN>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">I've
got two submit handlers for a form. The first validates the
form<BR>entries. The second submits the form as a web service call
(AJAX). I'm<BR>using $(form).submit( fValidate ) followed by
$(form).submit( fSubmit ). <BR>fValidate() returns false when validation fails
but fSubmit still fires.<BR>Shouldn't jQuery's handleEvent() stop processing
after a handler returns<BR>false? (see change
below.)<BR><BR>function handleEvent(event)
{<BR> var returnValue =
true;<BR> event = event ||
fixEvent(window.event);<BR> var
handlers = [];<BR> for ( var i
in this.events[event.type]
)<BR> handlers[handlers.length]
= this.events
[event.type][i];<BR> for ( var
i = 0; i < handlers.length; i++ )
{<BR> try
{<BR> if
( handlers[i].constructor == Function )
{<BR> this.$$handleEvent
= handlers[i];
<BR> if
(this.$$handleEvent(event) === false)
{<BR> event.preventDefault();<BR> event.stopPropagation();<BR> //returnValue
= false;
<BR> return
false; //
fix?<BR> }<BR> }<BR> }
catch(e){ }<BR> }<BR> return
returnValue;<BR>};<BR><BR><BR>_______________________________________________<BR>jQuery
mailing list<BR><A
href="mailto:discuss@jquery.com">discuss@jquery.com</A><BR><A
href="http://jquery.com/discuss/">http://jquery.com/discuss/</A><BR></BLOCKQUOTE></DIV><BR></BODY></HTML>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/