Ticket #2529282 (closed defect)

Reporter


Jeroen Versteeg
Opened: 09/6/10
Last modified: 08/18/11
Status: closed
Type: defect
Resolution: fixed

Owner


Luke Smith
Target Release: 3.4.0
Priority: P3 (normal)
Summary: Y.on( 'available' ) docs need to be clear about wanting a selector
Description:


Y.one( 'available', function () {}, Y.one( '#some input' );

Throws JS errors: "s.replace is not a function" and "J.match is not a function". In both cases, the object (s/J) is the DOM Node instead of a Y.Node object.

See the URL I provided for a simple test case. The expected outcome is that the input gets focus when it's available.
I tried this with 3.1.1 and 3.1.0 too, with the same result.

A propos: What I'm trying to do is focus() on an input I create (and append) through Y.Node. The code in the example shouldn't throw errors, but maybe I'm going about this the wrong way anyway?

Type: defect Observed in Version: 3.1.2
Component: Event Severity: S3 (normal)
Assigned To: Luke Smith Target Release: 3.4.0
Location: API Documentation Priority: P3 (normal)
Tags: Relates To:
Browsers: Firefox 3.x - All,IE 7.x,IE 8.x
URL: http://www.jayvee.nl/yuitest/buggy.html
Test Information:

Change History

Jeroen Versteeg

YUI Contributor

Posted: 09/6/10

Addendum: In the description's first line, "Y.one" should be "Y.on" of course.

Adam Moore

YUI Contributor

Posted: 09/7/10
  • priority changed to P3 (normal)
  • status changed from new to infoneeded

[code] var inp = Y.one( '#main input' );

// This will cause errors
Y.on( 'available', function () {
inp.focus();
console.log( inp + ' became available' );
}, inp );
[/code]
Yes, 'available' is expecting a selector to test -- if your reference is null it will throw an error. replace 'inp' with the selector string and it should work.

[code]
// This doesn't result in any action:
/*
Y.on( 'load', function () {
inp.focus();
console.log( inp + ' loaded' );
}, inp );
*/

[/code]

The input field doesn't have a load event.

Jeroen Versteeg

YUI Contributor

Posted: 09/7/10
  • status changed from infoneeded to assigned

Ah, I hadn't realized 'available' requires a selector! Now that I look at the example, it isn't very clear! I think this deserves some notice as it differs from other events.

Secondly, wouldn't it be better to have Y.on throw an Exception (or return null) if the wrong parameter type is used for 'available'?

My issue is solved anyway, thanks for the quick feedback!

Adam Moore

YUI Contributor

Posted: 09/7/10
  • location changed to Example
  • milestone changed to 3.3.0
  • status changed from assigned to accepted
  • summary changed from Y.on( 'available' ) causes errors to Y.on( 'available' ) docs need to be clear about wanting a selector

Jeroen Versteeg

YUI Contributor

Posted: 09/21/10

Adam, would it be possible to make Y.on( 'available' ) accept Y.Node instances as well as selectors?

I often have problems with IE(7) if I try to do something to nodes immediately after I've append()ed them to the DOM (e.g. simulate( 'focus') or apply an Anim()ation). Providing a selector pretty much requires an id (other ways of ensuring a particular unique element is selected are difficult, especially when you're creating DOM nodes dynamically), but I usually don't set one because it's not needed.

What I'm proposing is that Y.on( 'available' ) accepts a Y.Node. To implement, maybe it could then just use the nodes _yuid property to build a selector by itself?

Alternatively, is there some other way of delaying code until they're ready in IE (and other "slow" browsers)?
[code]
var inp = Y.Node.create( '<input type="text" name="foo">' );
Y.one( '#form' ).append( inp );
Y.on( 'available', function () { inp.simulate('focus'); }, inp ); // doesn't work in IE
[/code]

Adam Moore

YUI Contributor

Posted: 09/21/10

Why are you using the available event at all? That element should already be available, so that line should just be:
inp.simulate('focus');

Jeroen Versteeg

YUI Contributor

Posted: 09/22/10

Consider [url=http://www.jayvee.nl/yuitest/available.html]this example[/]
[code]
var inp = Y.Node.create( '<input name="test" type="text">' );
Y.one( '#main' ).append( inp );

Y.on( 'available', function () { // not required in FF
inp.focus();
}, '#main input' );
[/code]
If I append an input and try to get it to focus, this works fine in FireFox, but IE(7/8) won't do it. The weird thing is that in this test, trying to focus() doesn't work reliably at all, even if I add the Y.on( 'available' ) callback! I've also tried inp.simulate( 'focus' ) but get the same result.

I've got something very similar (but more complex) in a page and it works. Could it be that because this page is so small IE gets into timing issues?

Adam Moore

YUI Contributor

Posted: 10/27/10
  • milestone changed from 3.3.0 to 3.NEXT

George

YUI Developer

Posted: 04/20/11

Luke Smith

YUI Contributor

Posted: 04/28/11
  • location changed from Example to API Documentation
  • milestone changed from 3.NEXT to 3.4.0
  • status changed from assigned to accepted

I'll update the docs to be more explicit about 'available' and 'contentready' needing selectors.

For support with your use case, please ask in the forums (http://yuilibrary.com/forum) or in the #yui irc channel on irc.freenode.org.

Luke Smith

YUI Contributor

Posted: 06/28/11
  • estimated changed from 0 to .1
  • remaining changed from 0 to .1
  • sprint changed to sprint 3

Luke Smith

YUI Contributor

Posted: 07/27/11
  • completed changed from 0 to .1
  • remaining changed from 0.1 to 0
  • status changed from accepted to checkedin

George

YUI Developer

Posted: 08/18/11
  • resolution changed to fixed
  • status changed from checkedin to closed