This project is archived and is in readonly mode.

#453 ✓resolved
Roman

Selectors.Filters.byAttribute incorrect behavior

Reported by Roman | October 31st, 2008 @ 06:10 PM | in 1.3.0 rc2 (closed)

this function worked perfectly fine in 1.2.0 however in 1.2.1, one line was changed and it no longer works correctly...

i use it to get all td elements with non empty names:


my_parent_element.getElements('td[name!=]');

current code ignores that and returns all child td elements:


byAttribute: function(self, name, operator, value){
	var result = Element.prototype.getProperty.call(self, name);
	if (!result) return (operator == '!=');
	if (!operator || value == undefined) return true;
	switch (operator){
		case '=': return (result == value);
		case '*=': return (result.contains(value));
		case '^=': return (result.substr(0, value.length) == value);
		case '$=': return (result.substr(result.length - value.length) == value);
		case '!=': return (result != value);
		case '~=': return result.contains(value, ' ');
		case '|=': return result.contains(value, '-');
	}
	return false;
}

code from 1.2.0 that worked perfectly fine:


byAttribute: function(self, name, operator, value){
	var result = Element.prototype.getProperty.call(self, name);
	if (!result) return false;
	if (!operator || value == undefined) return true;
	switch (operator){
		case '=': return (result == value);
		case '*=': return (result.contains(value));
		case '^=': return (result.substr(0, value.length) == value);
		case '$=': return (result.substr(result.length - value.length) == value);
		case '!=': return (result != value);
		case '~=': return result.contains(value, ' ');
		case '|=': return result.contains(value, '-');
	}
	return false;
}

Comments and changes to this ticket

  • Nikolaj

    Nikolaj February 6th, 2009 @ 04:06 PM

    Hey Roman.

    I think your issue is reltated to my ticket, #403.

    I did ask that they reverted the change before 1.2.1, since only some things were changed - but it seems like it wasn't reverted in the end anyway.

    I'm also looking forward for the Selectors to be fixed fully, since it doesn't work in every case - neither in 1.2.0 nor 1.2.1.

    The difference in byAttribute between 1.2.0 and 1.2.1 is: [1.2.0] if (!result) return false; [1.2.1] if (!result) return (operator == '!=');

    You could try use the following code (which works out as expected): [my version] if (!result) return ((operator == '!=' && value != '') || (operator == '=' && value == ''));

  • Nikolaj

    Nikolaj February 6th, 2009 @ 04:07 PM

    Hmm.. Formatting got lost, but hope you'll manage to read/view it anyway :)

  • fakedarren

    fakedarren February 8th, 2010 @ 05:11 PM

    • State changed from “new” to “resolved”
    • Assigned user changed from “Valerio” to “fakedarren”
    • Milestone changed from 2.0 to 1.3.0 rc2

    Hey Roman,

    If you follow the discussion in the related issue (#403) you'll see this has been resolved in the next release (with Slick)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Referenced by

Pages