#3016 closed bug (patchwelcome)
Textarea loses current value when cloned
Reported by: | Jones | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | manipulation | Version: | 1.4.3 |
Keywords: | firefox textarea value clone | Cc: | |
Blocked by: | Blocking: |
Description
If you clone an element with a textarea in it and append this to another element, the value of the textarea is lost (or - if in the html a value for the textarea was set - the default value is set).
I found this behaviour only in firefox. I've attached a file with an example (and a dirty workaround I used).
Attachments (1)
Change History (25)
Changed 15 years ago by
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
will this be fixed? as I see it's a bug for more than 2 years now..
comment:3 Changed 14 years ago by
I have the same problem :-( Currently using a really ugly workaround...
I don't know too much about Trac, but maybe this bug report does not show up anymore, since it is assigned to Milestone 1.3. But I have no rights to change that...
Eddie
comment:4 Changed 13 years ago by
Component: | core → manipulation |
---|
comment:5 Changed 13 years ago by
Summary: | Problems with textareas, its value, clone and firefox → Textarea loses current value when cloned |
---|
comment:6 Changed 13 years ago by
Milestone: | 1.3 → 1.4.3 |
---|
comment:7 Changed 13 years ago by
This is actually a firefox bug and it's know and sits there unfixed since 2004
comment:8 Changed 13 years ago by
Keywords: | firefox, textarea, value, clone → firefox textarea value clone |
---|---|
Milestone: | 1.4.3 |
Priority: | major → low |
Status: | new → open |
Version: | 1.2.6 → 1.4.3 |
Safari and Chrome both do the same thing as Firefox here and clone the state of the element without any value changes. Opera and IE clone current state of the control, including any value changes. Fun…
comment:10 Changed 13 years ago by
Resolution: | → patchwelcome |
---|---|
Status: | open → closed |
This is similar to #1736 (if not an outright dup) and seems equally difficult to fix in a general way. If someone needs the partial input typed by a user at the point of cloning it would make more sense to copy over the .value at that point. If someone has a better idea let us know.
comment:11 Changed 12 years ago by
Bug still exists in jQuery 1.6.2
Maybe this would be a solution? https://github.com/spencertipping/jquery.fix.textarea-clone
comment:14 Changed 11 years ago by
I need this because I simulate nested forms by cloning parts of a big form, wrapping them in their own form, and submitting. I'm going to have to use @jakobbhilden's approach (thanks!).
My feeling is that if cloning other elements and getting their values works as expected, so should it word for textareas. So yes, the value should be copied when the element is cloned. Otherwise, it's simply not a "clone".
comment:15 follow-up: 16 Changed 11 years ago by
Experiencing this bug in Chrome now. How come this ticket is closed?
comment:16 Changed 11 years ago by
Replying to Val Schuman <jquery@…>:
Experiencing this bug in Chrome now. How come this ticket is closed?
Same here.
comment:17 Changed 11 years ago by
It's closed as "patchwelcome", which means we're not going to fix it ourselves because we believe it to be too difficult, as dmethvin says:
"If someone needs the partial input typed by a user at the point of cloning it would make more sense to copy over the .value at that point. If someone has a better idea let us know."
comment:18 Changed 11 years ago by
It doesn't actually look "too difficult" based on the fix by Spencer Tipping here:
https://github.com/spencertipping/jquery.fix.clone/blob/master/jquery.fix.clone.js
It is quite confusing when standard text inputs are cloned with their live value whereas textareas are not. :-(
comment:19 Changed 11 years ago by
Wierd bug... I'd suggest this should be fixed not because I'm lazy but because as others have said it's inconsistent behaviour when compared to how clone() handles other elements. clone() should clone, not clone most of it but leave little bits out here and there. Also the current clone() man page doesn't make any mention of this behaviour, which could be confusing.
comment:20 Changed 11 years ago by
I consider this a bug that should remain open, as others have said. I don't know the ins and outs of jQuery's clone function, but this was my workaround,...
I simply set all textarea values within the "to-be-cloned" container into an obscurely-named "data-" attribute of each area before the clone, then restored the area values from the attributes immediately after (and removed the obscurely-named attribute). Sure, there's a performance/memory penalty but well worth it for all of my uses.
comment:21 Changed 10 years ago by
I definitely think this should be fixed. I can verify that this did solve the problem for me.
https://github.com/spencertipping/jquery.fix.clone/blob/master/jquery.fix.clone.js
My use case involves cloning but not appending: the user is filling out a form which, when saved to the database, will be used to create a printable document. They can preview the document at any time. To generate the preview, I clone the form, set its action and target so that it will update an iframe with the printable version, and call .submit().
comment:22 Changed 10 years ago by
I believe that this bug is still in place. I was trying to clone divs from one form to another. All of the inputs were using the current value, but the textarea wasn't. In my case, I was able to just use appendTo instead of clone, but I think this is something that should be looked at.
I am using jQuery v1.10.2
comment:23 Changed 10 years ago by
This is still a problem with the latest 2.x and 1.x code, in Chrome 30 and Firefox 25; check this jsfiddle demonstrating it: http://jsfiddle.net/bLxsC/
comment:24 Changed 10 years ago by
The current behavior is documented at api.jquery.com and of course here. A plugin is available to provide the requested behavior. The ticket is marked patchwelcome, with the caveat that fixing this edge case inside jQuery causes a performance hit for the 90% of the time when it isn't needed.
This problem is not fixed. I get this problem on version 1.3.2.