Bug Tracker

Ticket #4389 (closed bug: fixed)

Opened 6 years ago

Last modified 3 years ago

$().removeAttr('maxlength') set maxlength to 0 in IE7

Reported by: lyndsysimon Owned by:
Priority: minor Milestone:
Component: core Version: 1.3.1
Keywords: removeAttr maxlength Cc:
Blocking: Blocked by:

Description

When you use .removeAttr, IE does not let you enter anything in the field. IE Dev Toolbar on IE7 reports that maxlength=0.

Attachments

test.htm Download (545 bytes) - added by lyndsysimon 6 years ago.

Change History

Changed 6 years ago by lyndsysimon

comment:1 Changed 6 years ago by lyndsysimon

After further testing, it appears that .removeAttr('maxLength') works in both IE7 and Ffx 3.0.6. Still not correct behavior, but it solves my immediate issue.

comment:2 Changed 6 years ago by lyndsysimon

to clarify, 'maxLength' works, 'maxlength' does not.

comment:3 Changed 6 years ago by dmethvin

Can you clarify what the original problem was? Were you trying to "clear" maxlength so that the field wasn't constrained?

NB: There is actually a .maxLength *property* on input elements; IE and Firefox do not treat the "no max length" the same way. I seem to recall that IE uses -1 and FF uses 231.

comment:4 Changed 6 years ago by lyndsysimon

Perhaps I am using it in the wrong way, then. My initial frustration was with removing the maxlength from a text input, to instead color the field when the maximum length was exceeded - as part of an unobtrusive form validation script.

<input type='text' id='target' maxlength='3'>

The above limits the field to 3 characters - no more may be entered. Now if we execute this:

$('input#target').removeAttr('maxlength');

The limitation is removed in Firefox (so the field now has no maximum length), but it is changed to 0 in IE7, so you cannot input any characters at all. If I use this instead (notice capitalization):

$('input#target').removeAttr('maxLength');

it works properly in all three major browsers.

comment:5 Changed 5 years ago by dmethvin

Hmmm, maybe adding maxlength to jQuery.props would fix this?

comment:6 Changed 5 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in 1.4a1; maxLength is in jQuery.props.

comment:7 Changed 4 years ago by blaisekal@…

This (still? again?) seems to be a problem:  http://jsfiddle.net/dcrQg/

Note: See TracTickets for help on using tickets.