Side navigation
#8232 closed bug (patchwelcome)
Opened February 10, 2011 11:48AM UTC
Closed February 11, 2011 01:05AM UTC
Last modified March 14, 2012 08:18PM UTC
.attr can't change a submit input
Reported by: | remysharp | Owned by: | remysharp |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | attributes | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Changing a submit input element to a button (or perhaps another type) causes jQuery to throw a fatal exception:
$('input[type=submit]').attr('type', 'button'); // throws fatal
Working example: http://jsbin.com/arida/2
Note that it throws an exception (which is why I've wrapped them in a try/catch for the example).
Broken in: Chrome 9, Firefox 3.6.x, Safari 5 (not, as jitter had, just IE).
Attachments (0)
Change History (13)
Changed February 10, 2011 12:48PM UTC by comment:1
component: | unfiled → attributes |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
Changed February 10, 2011 05:43PM UTC by comment:3
Actually this also seems to also happen in Chrome (9.0.597.84 beta) and Firefox (3.6.13).
Changing a submit button's type attribute nodeValue to button (ie without using jQuery), works in these browsers.
So I think this is a bug in jQuery
Changed February 10, 2011 07:21PM UTC by comment:4
Replying to [comment:3 Adrian Mester <mesteradrian@…>]:
Actually this also seems to also happen in Chrome (9.0.597.84 beta) and Firefox (3.6.13). Changing a submit button's type attribute nodeValue to button (ie without using jQuery), works in these browsers. So I think this is a bug in jQuery
Yes this happens in every browser and purposefully so. #1536 and 7d02f06e
Changed February 10, 2011 11:38PM UTC by comment:5
Replying to [comment:1 jitter]:
Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case! This is a bug in Internet Explorer that can't be worked around (IE doesn't allow the type attribute to be changed). There is a note about this on http://api.jquery.com/jQuery/ . I notified the api documentation team to add this missing hint to the .attr()
api page too.
Erm...I didn't test IE. It's happening in Chrome 9, Safari 5 and Firefox 3.6.x. I assume the test case wasn't even opened then?
Changed February 10, 2011 11:39PM UTC by comment:6
description: | Changing a submit input element to a button (or perhaps another type) causes jQuery to throw a fatal exception: \ \ \ {{{ \ $('input[type=submit]').attr('type', 'button'); // throws fatal \ }}} \ \ \ Working example: [http://jsbin.com/arida/2] \ \ Note that it throws an exception (which is why I've wrapped them in a try/catch for the example). → Changing a submit input element to a button (or perhaps another type) causes jQuery to throw a fatal exception: \ \ \ {{{ \ $('input[type=submit]').attr('type', 'button'); // throws fatal \ }}} \ \ \ Working example: [http://jsbin.com/arida/2] \ \ Note that it throws an exception (which is why I've wrapped them in a try/catch for the example). \ \ Broken in: Chrome 9, Firefox 3.6.x, Safari 5 (not, as jitter had, just IE). |
---|---|
resolution: | invalid |
status: | closed → reopened |
Changed February 11, 2011 12:10AM UTC by comment:7
_comment0: | Replying to [comment:5 remysharp]: \ > Erm...I didn't test IE. It's happening in Chrome 9, Safari 5 and Firefox 3.6.x. I assume the test case wasn't even opened then? \ Umm.. ~~wtf~~ of course I opened the test case - and no not with IE - after reading the report, I also checked the source. So, yes I saw (but also knew there would be one without checking) the exception in a non IE browser. \ \ My answer stands as it is! Did you read my [http://bugs.jquery.com/ticket/8232?replyto=5#comment:4 comment] and the links there?? \ > Yes this happens in every browser and purposefully so. #1536 and [https://github.com/jquery/jquery/commit/7d02f06e036f6a42ccd2c276e9f00a7cd35dc74a 7d02f06e] \ \ Let me [http://bugs.jquery.com/ticket/1536#comment:2 quote John directly] \ > Attempting to do this now throws an exception in all browsers \ \ So this behavior isn't a bug. The error is thrown on purpose, because this is something that can't be worked around in IE. So we disallow it for all browsers because else people do this and then wonder why it doesn't work in IE. → 1297383401712977 |
---|---|
owner: | → remysharp |
status: | reopened → pending |
Replying to [comment:5 remysharp]:
Erm...I didn't test IE. It's happening in Chrome 9, Safari 5 and Firefox 3.6.x. I assume the test case wasn't even opened then?
Umm.. ~~wtf~~ of course I opened the test case - and no not with IE - after reading the report, I also checked the source. So, yes I saw the exception in a non IE browser (but also knew there would be one without checking).
My answer stands as it is! Did you read my comment and the links there??
Yes this happens in every browser and purposefully so. #1536 and 7d02f06e
Let me quote John directly
Attempting to do this now throws an exception in all browsers
So this behavior isn't a bug. The error is thrown on purpose, because this is something that can't be worked around in IE. So we disallow it for all browsers because else people do this and then wonder why it doesn't work in IE.
Changed February 11, 2011 01:05AM UTC by comment:8
_comment0: | @remysharp As I know you are a very capable JavaScript programmer, I'm going to close this as "patchwelcome". John's own commit message and Anton(jitter)'s thorough research support this behaviour as being valid - but we welcome you to solve the issue. → 1297387284945373 |
---|---|
resolution: | → patchwelcome |
status: | pending → closed |
@remysharp As I know you are a very capable JavaScript programmer, I'm going to close this as "patchwelcome". John's own commit message and Anton(jitter)'s thorough research supports this behaviour as being valid - but we welcome you to solve the issue.
Changed February 11, 2011 01:59AM UTC by comment:9
I'm pretty sure there's a miscommunication here.
Changing the input type with jQuery will throw an exception, due to 7d02f06e
But changing the input type in JavaScript generally does not throw an exception, except in IE.
There are plenty of instances in which jQuery is used without concern for IE. So perhaps jQuery shouldn't amputate attr()s functionality for all browsers..
Changed February 11, 2011 03:04AM UTC by comment:10
@paul.irish As the closing status says "patchwelcome"
Changed February 11, 2011 04:14PM UTC by comment:11
_comment0: | Removing the thrown error doesn't fix Remy's code in the video here, where he calls this a "bug in jQuery" but certainly he must not have intended to create code that IE won't run: \ \ http://jqueryfordesigners.com/video.php?f=select-boxes.mp4 \ \ Even if we remove the thrown error, the code will seem to work just peachy when tested in webkit/firefox and then bite everyone who doesn't test in IE and/or doesn't understand the underlying issue. \ \ The reason this was put in originally was because people wanted jQuery to be "cross-browser" and behave consistently with respect to this problem. If we revert the behavior so that it tries to set the type of the button, it *will* die in IE. The code to totally work around the problem in IE -- create a new element, copy over attributes, data and events, replace the old element -- is not worth it IMO. But the ticket says patchwelcome; maybe someone can come up with a small, fast, well-tested fix. \ \ I am also totally OK with reverting this check and letting IE alone die, but we've gone back and forth on it for five years. If everyone in the room now will make a blood pact that this is really the right thing to do and we shall never again speak of it, we could set #1536 (that patched it three years ago to generate an error), #5544, #1957, #1359, and #120 (me five years ago!) to wontfix and let the world fend for itself on IE. I think it will still continue to create tickets either way. \ \ → 1297441509529195 |
---|
Removing the thrown error doesn't fix Remy's code in the video here, where he calls this a "bug in jQuery" but certainly he must not have intended to create code that IE won't run:
http://jqueryfordesigners.com/video.php?f=select-boxes.mp4
Even if we remove the thrown error, the code will seem to work just peachy when tested in webkit/firefox and then bite everyone who doesn't test in IE and/or doesn't understand the underlying issue.
The reason this was put in originally was because people wanted jQuery to be "cross-browser" and behave consistently with respect to this problem. If we revert the behavior so that it tries to set the type of the button, it *will* die in IE. The code to totally work around the problem in IE -- create a new element, copy over attributes, data and events, replace the old element -- is not worth it IMO. But the ticket says patchwelcome; maybe someone can come up with a small, fast, well-tested fix. The upcoming 1.6 attrHooks would make this easy to do as a plugin.
I am also totally OK with reverting this check and letting IE alone die, but we've gone back and forth on it for five years. If everyone in the room now will make a blood pact that this is really the right thing to do and we shall never again speak of it, we could set #1536 (that patched it three years ago to generate an error), #5544, #1957, #1359, and #120 (me five years ago!) to wontfix and let the world fend for itself on IE. I think it will still continue to create tickets either way.
Changed February 15, 2011 03:33PM UTC by comment:12
Okay, misunderstood @jitters test - I see what we're dealing with now. Let us put our handbangs back down and chill :)
Honestly, it feels pretty weird that jQuery is replicating a bug in IE, but I can understand there's been more than a quick pint and chat about that decision.
The way I see it, is there's two good ways to approach this rather specific, but obtuse bug:
1. a touch more detail in the exception description ("the type cannot be changed" - I just figured it was the usual crap that IE errors throw "there was an error in the script", etc) - or at least a link pointing to /why/ it's like that (not just to the .attr api docs, at least to an anchor point in the page).
2. As Dave suggested, clone the element and replace it. I don't see this as a terrible idea, it certainly fixes an age old issue in IE, rather than replicating one.
Either way, Rick's marked it as #patchwelcome, so it's all fair game.
Cheers.
- Remy.
Changed February 20, 2011 01:58AM UTC by comment:13
#8329 is a duplicate of this ticket.
Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!
This is a bug in Internet Explorer that can't be worked around (IE doesn't allow the type attribute to be changed). There is a note about this on http://api.jquery.com/jQuery/ . I notified the api documentation team to add this missing hint to the
.attr()
api page too.