This project is archived and is in readonly mode.

#398 ✓duplicate
VirtuosiMedia

removeProperty doesn't work with lowercase maxlength

Reported by VirtuosiMedia | September 27th, 2008 @ 12:14 AM

It seems that removeProperty() doesn't work for maxlength unless maxlength is capitalized or camelCased. For instance, on the following form input:

These both work:

$('name').removeProperty('MAXLENGTH'); $('name').removeProperty('maxLength');

But this will only set the value of maxlength to 0, not remove it:

$('name').removeProperty('maxlength');

Comments and changes to this ticket

  • VirtuosiMedia

    VirtuosiMedia September 27th, 2008 @ 12:15 AM

    Sorry, didn't realize it didn't take HTML. The form input is simply:

    [input id="name" type="text" name="name" maxlength="10" /]

  • VirtuosiMedia

    VirtuosiMedia September 27th, 2008 @ 12:22 AM

    One more clarification: I was using Firefox 2.0.0.17.

    Also, I didn't test it, but could this be the case for any attribute that is normally camelCased in JavaScript, but not in HTML?

  • Tom Occhino

    Tom Occhino October 13th, 2008 @ 06:16 PM

    • Assigned user changed from “Valerio” to “Tom Occhino”
    • State changed from “new” to “open”
    • Milestone changed from 2.0 to 1.2.3

    Confirmed, I wish I could fix this for 1.2.1, but we are afraid the fix will cause other issues we don't know about yet.

    VirtuosiMedia, for now, use removeAttribute, and i will work on getting a fix in for this and a few related issues asap.

  • Fábio M. Costa

    Fábio M. Costa November 29th, 2008 @ 01:57 PM

    Yep this really happens. It isn't removed on ie6-7 and opera too (just works on webkit browsers, i just tested this).

    Adding:

    
    Element.Properties.maxlength = {
     erase: function(){
      this.removeProperty('maxLength');
     }
    };
    

    Would make this possible:

    
    $('input_test').erase('maxlength');
    

    But as Tom said... i don't know if this is going to cause other issues.

  • Tom Occhino

    Tom Occhino November 29th, 2008 @ 04:34 PM

    There's no way we would be able to add a special get / set / erase for every single 'special' property, however, we do need to handle the problem in getProperty / removeProperty, unfortunately the fix causes other problems. We just need to come up with a better fix. :)

  • Fábio M. Costa

    Fábio M. Costa November 30th, 2008 @ 03:28 PM

    the problem is just on removeProperty and i was looking at the function and there may be a fix, i didnt check if it works ok for every case, but for maxlengt it works ok.

    
    removeProperty: function(attribute){
     var key = attributes[attribute];
     if(key){
      this[key] = (key && bools[attribute]) ? false : '' ;
      this.removeAttribute(key);
     }
     return this;
    },
    

    don't know if it does what you guys want and fix the problem. I don't understand why the actual version doesn't remove the attribute every time. Shouldn't it?

  • Fábio M. Costa

    Fábio M. Costa November 30th, 2008 @ 03:36 PM

    better version...

    
    removeProperty: function(attribute){
     var key = attributes[attribute];
     if(key){
      if(bools[attribute])
       this[key] = false;
      else
       this.removeAttribute(key);
     }
     return this;
    },
    
  • Fábio M. Costa

    Fábio M. Costa November 30th, 2008 @ 05:35 PM

    a better candidate:

    removeProperty: function(attribute){ var key = attributes[attribute]; if(key) ( bools[attribute] ) ? this[key] = false : camels[attribute] ? this.removeAttribute(key) : this.removeAttribute(attribute); return this; },

  • Fábio M. Costa

    Fábio M. Costa November 30th, 2008 @ 05:37 PM

    sorry, remove my last comment please.

    a better candidate:

    
    removeProperty: function(attribute){
     var key = attributes[attribute];
     if(key) ( bools[attribute] ) ? this[key] = false : camels[attribute] ? this.removeAttribute(key) : this.removeAttribute(attribute);
     return this; },
    
  • Fábio M. Costa

    Fábio M. Costa November 30th, 2008 @ 06:42 PM

    now it looks better:

    
    removeProperty: function(attribute){
     var key = attributes[attribute];
     if(key) bools[attribute] ? this[key] = false : camels[attribute] ? this.removeAttribute(key) : this[key] = '';
     else this.removeAttribute(attribute);
     return this;
    },
    

    sorry for the 'flood'.

  • Fábio M. Costa

    Fábio M. Costa December 1st, 2008 @ 04:44 AM

    better tested:

    
    removeProperty: function(attribute){
     var key = attributes[attribute];
     if(key) (bools[attribute]) ? this[key] = false : camels.contains(key) ? this.removeAttribute(key) : this[key] = '';
     else this.removeAttribute(attribute);
     return this;
    },
    

    sorry another time...

  • Fábio M. Costa

    Fábio M. Costa June 15th, 2009 @ 04:30 AM

    • Assigned user changed from “Tom Occhino” to “Aaron Newton”

    take a look at this (forget about all the code i wrote on the other comments):

    http://meiocodigo.com/mootools-tests/maxlength.html

  • Thomas Aylott
  • Aaron Newton

    Aaron Newton February 9th, 2010 @ 09:01 AM

    • Assigned user changed from “Aaron Newton” to “Valerio”

    this is a -core bug; reassigning to valerio.

  • Valerio

    Valerio February 16th, 2010 @ 02:36 PM

    I am not sure if removeProperty (or erase()) should support all-lowerCase attribute names. I am not sure why it works with a capitalized string, it should not.

  • Fábio M. Costa

    Fábio M. Costa February 20th, 2010 @ 02:09 AM

    it works with a capitalized string.
    You can close this as duplicate as its pointed out at #747

    https://mootools.lighthouseapp.com/projects/2706/tickets/747-setget...

  • fakedarren

    fakedarren February 21st, 2010 @ 10:36 AM

    • State changed from “open” to “duplicate”

Create your profile

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

Shared Ticket Bins

Referenced by

Pages