bug? only single onmatch is called among multiple onmatch declarations

42 views
Skip to first unread message

Venkat

unread,
Feb 27, 2010, 1:49:33 PM2/27/10
to jQuery Entwine
I have a textfield with two classes, inline-label and ajax-validate.

I have code of this form:

$('.inline-label').entwine({
onmatch: function() {
...
console.log('.inline-label onmatch');
this._super();
},
onunmatch: function() {
...
console.log('.inline-label onunmatch');
this._super();
});

If I add the following entwine declaration:

$('input.ajax-validate').entwine({
onmatch: function() {
this._super();
},
onunmatch: function() {
this._super();
});

Then the onmatch does not get called for the .inline-label entwine
declaration. Is this a bug or am I not doing something correctly?

Thanks!

hamish

unread,
Feb 28, 2010, 3:18:04 PM2/28/10
to jQuery Entwine
Hmm. There is a known bug with onmatch (described below), but the
given code should work fine - a textarea isn't going to match
input.ajax-validate, so there shouldn't be any interference with the
original block.

Can you send me a DOM snippet? That way I can write a test for the
exact structure that's failing.

The known bug is that, unlike with other events & functions, declaring
two blocks with _the same selector_ won't set up inheritance, but will
just overwrite the definition.

$('.foo').entwine({
bar: function(){ console.log('bar:1'); }
onmatch: function(){ console.log('onmatch:1'); }
})

$('.foo').entwine({
bar: function(){ console.log('bar:2'); this._super(); }
onmatch: function(){ console.log('onmatch:2'); this._super(); }
})

Given that, onmatch will only log 'onmatch:2', whereas calling $
(element).bar() will log 'bar:2' then 'bar:1'. I've got an uncommitted
fix for this - I must remember to commit it.

Hamish

Venkat

unread,
Feb 28, 2010, 3:36:45 PM2/28/10
to jQuery Entwine
Here is an illustration of the bug.

The output of the following test is:
bar
foo method
bar method

The foo and bar methods are correctly attached to the element.
However, only the onmatch handler for bar is called.

<html>

<head>
<title>Entwine Bug</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.entwine-dist.js"></
script>

<script type="text/javascript">
(function($) {
$('.foo').entwine({
onmatch: function() {
console.log('foo');
},
onunmatch: function() {

},
foo: function() {
console.log('foo method');
}
});

$('.bar').entwine({
onmatch: function() {
console.log('bar');
},
onunmatch: function() {

},
bar: function() {
console.log('bar method');
}
});

$(document).ready(function() {
$('#element').foo();
$('#element').bar();
});

})(jQuery);
</script>
</head>

<body>

<div id="element" style="width: 100px; height: 100px; border: 1px
solid;" class="foo bar"></div>

</body>

</html>

Josh Hundley

unread,
Feb 28, 2010, 3:52:09 PM2/28/10
to jquery-...@googlegroups.com
Nice. I hadn't realized that was a bug. I guess I figured inheritance
was based solely on css specificity.

Hey, Hamish, are you using entwine in any "real-world" apps? Haven't
seen much activity here lately, and it's nice to know I'm not the only
one using this :).

Josh

Sent from my iPhone

Venkat

unread,
Feb 28, 2010, 3:57:07 PM2/28/10
to jQuery Entwine
I just realized that if I call _super at the end of both onmatch
calls, it works. In this isolated example, it works fine. But, for
some reason in my application it is not working. Maybe it's something
I'm doing... I'll post back if I'm able to reproduce this as a bug.

I'm baffled as to why entwine hasn't gotten much traction!

hamish

unread,
Feb 28, 2010, 4:19:49 PM2/28/10
to jQuery Entwine

> Nice. I hadn't realized that was a bug. I guess I figured inheritance  
> was based solely on css specificity.

Ah, but position is the last element in css specificity (it's included
in the css spec in the specificity calculation section). I need to
make the documentation clearer about this I think.

> Hey, Hamish, are you using entwine in any "real-world" apps? Haven't  
> seen much activity here lately, and it's nice to know I'm not the only  
> one using this :).

Yeah, it's under pretty much constant use, including in a couple of
pretty big web apps. The reason I haven't done anything on it lately
is that it does everything I need. I don't really believe in adding
API just for the sake of it if there isn't any use case, and nobody's
really come back with feature requests.

That being said, I'll be putting together another release fairly soon.
It'll include a couple of bug fixes (this one and an issue with
onchange emulation in IE), and a couple of features that I'd almost
certainly use once they're more stable.

If you guys are feeling any pain points in using it, let me know.

Hamish

hamish

unread,
Feb 28, 2010, 4:27:45 PM2/28/10
to jQuery Entwine

> I just realized that if I call _super at the end of both onmatch
> calls, it works. In this isolated example, it works fine. But, for
> some reason in my application it is not working. Maybe it's something
> I'm doing... I'll post back if I'm able to reproduce this as a bug.

This is an area I could definitely stand to improve on - tracking down
the call chain on a complex site. I've been meaning to see how hard a
firefox extension would be that could show you what functions are
bound to what elements.

> I'm baffled as to why entwine hasn't gotten much traction!

Me too. I think it's partly lack of exposure - other than the one
Ajaxian post, there hasn't been that much visible news about it - and
partly a lack of instantly obvious payback. One of the reasons for a
new release is so we can have another round of announcements, try to
improve awareness. I'm also probably going to try and do an entwine
powered space invaders clone as an example / intro to entwine thingy.

A pretty logo & homepage would probably help too :).

Hamish

Josh Hundley

unread,
Feb 28, 2010, 5:29:31 PM2/28/10
to jquery-...@googlegroups.com
Ah, but position is the last element in css specificity (it's included
in the css spec in the specificity calculation section). I need to
make the documentation clearer about this I think.

Good to know. I'll have to read up on this!

If you guys are feeling any pain points in using it, let me know.

No problems to report here! Entwine has drastically changed my approach to JS development. I've even gotten a couple of my coworkers using it as well. Thanks!

Josh 
Reply all
Reply to author
Forward
0 new messages