This project is archived and is in readonly mode.

#403 ✓resolved
Nikolaj

Selectors filtering ignores empty class(name)

Reported by Nikolaj | October 4th, 2008 @ 11:39 AM | in 1.3.0 rc2 (closed)

When trying to find elements by the classname, the result isn't as expected. It seems like the filtering part is "ignoring" both undefined and empty attributes.

I noticed the problem, when trying to retrieve the reverse result of all links (A) with a specific class(name) - as in:


$$('a[class!=myname]')

when trying to get all other links than those with myname. This currently ignores all links that doesn't have min. 1 characters in the class(name).

Have attached an example (html-file) with different tests, in order to better display the issue.

Of course one could do:


$$('a').each(function (el) { if (el.hasClass('myname')) ... });

but then one will miss the fun with selectors :-)

Comments and changes to this ticket

  • Jan Kassens

    Jan Kassens October 4th, 2008 @ 11:59 AM

    • Assigned user changed from “Valerio” to “Jan Kassens”
    • State changed from “new” to “open”
    • Milestone changed from 2.0 to 1.2.1
    • Tag changed from bug, class, defect, element, selectors to selectors
  • Jan Kassens

    Jan Kassens October 4th, 2008 @ 12:31 PM

    • State changed from “open” to “resolved”

    Thanks Nikolaj, it's fixed now in the master.

  • Nikolaj

    Nikolaj October 7th, 2008 @ 06:42 PM

    Hello Jan.

    Just tested the committed code, but it doesn't seem to be working fully however.

    Actually, it makes the last test fail instead.

    1.2.0 code (Works: 1+2+3+6 / Fails: 4+5)

    
    if (!result) return false;
    

    Your fix (Works: 1+2+3+4+6 / Fails: 5+6 = Fixes #4, but makes #6 fail)

    
    if (!result) return (operator == '!=');
    

    I have then tried to test a bit further, and came to the following conclusion:

    Fix 1 (Works: 1+2+3+4+6 / Fails: 5 = Fixes #4 and leaves #6 still working)

    
    if (!result) return (operator == '!=' && value != '');
    

    Fix 2 (Works: 1+2+3+5+6 / Fails: 4 = Fixes #5)

    
    if (!result) return (operator == '=' && value == '');
    

    Final (Works: 1+2+3+4+5+6 / Fails: none = Fixes Test 4 + 5 and makes all tests (1-6) work as expected)

    
    if (!result) return ((operator == '!=' && value != '') || (operator == '=' && value == ''));
    

    Hope you'll update the code, or let me know if any other file(s) (than Source/Utilities/Selectors.js) needs to be changed in order to test it? :)

    Thanks!

  • Nikolaj

    Nikolaj October 7th, 2008 @ 06:44 PM

    The #4, #5, #6 is of course Test xxx - not other tickets :) hehe

  • Thomas Aylott

    Thomas Aylott October 12th, 2008 @ 02:58 PM

    • State changed from “resolved” to “open”
  • Tom Occhino

    Tom Occhino October 16th, 2008 @ 08:04 PM

    • Milestone changed from 1.2.1 to 1.2.3

    Nikolaj, we'd like to do a little more testing so I'm pushing this to 1.2.2 and we will include your fix there.

  • Nikolaj

    Nikolaj October 17th, 2008 @ 09:48 AM

    Hey Tom, thats okay - but seems like you forgot to revert the fix by Jan - so hope 1.2.2 isn't that far away then, so people won't have any weird issues with it :-) hehe

  • Nikolaj

    Nikolaj February 6th, 2009 @ 04:14 PM

    Due to the above mentioned issue, there was a placed a fix between 1.2.0 and 1.2.1.

    However, as stated on Oct. 17th, it should be have been reverted until it was fixed completely due to it would lead to another issue. This new issue has also appeared to another user, as stated in ticket #453.

    Hope you'll try to consider the following code (also stated on Oct 7th in this ticket):

    
    if (!result) return ((operator == '!=' && value != '') || (operator == '=' && value == ''));
    

    Thanks :)

  • Thomas Aylott

    Thomas Aylott March 17th, 2009 @ 01:32 AM

    • Milestone changed from 1.2.3 to 2.0
    • Tag changed from selectors to selectors, slick
    • Assigned user changed from “Jan Kassens” to “Thomas Aylott”

    fixed in slick. I'll be sure to add specs for this specific issue.

  • Thomas Aylott

    Thomas Aylott March 17th, 2009 @ 01:35 AM

    What is the logic of [attr!=val] supposed to be?

    imho it should be the same as [attr]:not([attr=val])

    != is a nonstandard operator. So I guess we should just make it work like all the other libraries out there currently work.

    Can anyone give me any other selector (no matter how complex) that should return the same results as [attr!=val] if my assumption is incorrect?

  • Thomas Aylott

    Thomas Aylott March 17th, 2009 @ 01:37 AM

    The other option would be to make [attr!=val] return the same results as :not([attr=val])

    Is that the expected behavior?

  • Nikolaj

    Nikolaj March 17th, 2009 @ 10:28 PM

    I suppose that [attr!=val] is the same as :not([attr=val]).

    I am just using "!=" since it is stated in the docs, whereas ":not" isn't: http://mootools.net/docs/Utiliti...:getElements

    As stated in the docs as well as in my mind, != is everything else than the specified. The != or :not(...) would be nice to have functioning since it can be used in different cases, ie. when you should update all elements without a specific classname or something.

    Anyway, thanks for fixing :)

  • Jan Kassens

    Jan Kassens November 21st, 2009 @ 03:08 PM

    • Tag changed from selectors, slick to slick

    should be :not([attr=value]) so you get all elements that don't have attr set to val. (no matter if its not set or set to something different)

  • Fábio M. Costa

    Fábio M. Costa April 4th, 2010 @ 11:50 PM

    • Milestone changed from 2.0 to 1.3.0 rc2
    • State changed from “open” to “resolved”

    Yes its fixed on slick, just checked it out. Will be on moo 1.3.

Create your profile

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

Shared Ticket Bins

Attachments

Tags

Referenced by

Pages