Search the web
Sign In
New User? Sign Up
ydn-javascript · Yahoo! User Interface Library Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Interesting Event Bug?   Message List  
Reply | Forward Message #36950 of 52119 |
Admittedly, the approach laid out below is naive and probably not best practice, but I encountered what appears to be an interesting bug, and I'm unsure if it's in YUI or the browsers event model (this bug appears in both Firefox and IE).

I have a page with a form on it, this form has a submit button and everything else a good form that doesn't support JavaScript should have. At the end of the page load, I have JavaScript that sets up the form with an event-based model, and gets rid of the buttons to provide a cleaner interface.  The function that removes the select button looks something like this:

var PrepareForm = function (form) {
  form.removeChild(form.submit_button);
}

And this method is set to be run as an event by using the onAvailable method, referring to the form.  But, the application may have multiple forms, so I decided to wrap up each form in a closure, that also wired up all the events for that form, so I did this:
var PrepareTestForm = function(form) {
  YAHOO.log("Inside PrepareForm");
  var RemoveElements = function () {
    YAHOO.log("Inside OnFormLoad");
    form.removeChild(form.submit_button);
  }
  var OnChangeHandler = function (e) {
    // Do stuff
  }

  YAHOO.util.Event.onAvailable(form, RemoveElements);
  YAHOO.tuil.Event.addListener(form.select_box, "change", OnChangeHandler);
}

But, I don't really want to register an onAvailable for a form that may not be loaded into the page, so rather than setting up an onAvailable call to PrepareTestForm when the "test_form" is available, and since I know the JavaScript is the last thing to run, I opted to put the following loop into the code:
for(var i = 0 ; i < document.forms.length ; i += 1) {
  switch(document.forms[i].id) {
    case "test_form":
      YAHOO.log("Call PrepareForm");
      PrepareTestForm(document.forms[i]);
      break;
    case "other_form":
      // Set up Form
    case "clown_form":
      // Set up Form.
  }
}

Now, what's interesting is the output of the log on the above code.  "Call PrepareForm" appears once.  "Inside PrepareForm" appears once.  "Inside OnFormLoad" appears twice?

If I register calls with onAvailable (both with onAvailable before and after the form's decleration), it works fine.  It's only when I do what I've done above that this occurs, and it's in both FIrefox (2/3) and IE 7.  I've put in some error checking code to make sure that errors aren't thrown when PrepareForm is called twice, but I'm not sure why it's getting called twice at all?  Am I missing something in the Browser Event Model?  Or is YUI doing something that I don't understand?

Jeff Craig


Fri Aug 29, 2008 11:37 pm

foxxtrot713
Online Now Online Now
Send Email Send Email

Forward
Message #36950 of 52119 |
Expand Messages Author Sort by Date

Admittedly, the approach laid out below is naive and probably not best practice, but I encountered what appears to be an interesting bug, and I'm unsure if...
foxxtrot713
Online Now Send Email
Aug 29, 2008
11:37 pm

Oh, and since I forgot to include it, I've put a sample page up here at: http://catalog.wsu.edu/event_test.html...
foxxtrot713
Online Now Send Email
Aug 29, 2008
11:39 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help