Bug Tracker

Ticket #3016 (closed bug: patchwelcome)

Opened 6 years ago

Last modified 9 months ago

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:
Blocking: Blocked by:

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

test.html Download (1.5 KB) - added by Jones 6 years ago.

Change History

Changed 6 years ago by Jones

comment:1 Changed 5 years ago by Sly777

This problem is not fixed. I get this problem on version 1.3.2.

comment:2 Changed 4 years ago by szrudi

will this be fixed? as I see it's a bug for more than 2 years now..

comment:3 Changed 4 years ago by Eddie

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 4 years ago by dmethvin

  • Component changed from core to manipulation

comment:5 Changed 4 years ago by dmethvin

  • Summary changed from Problems with textareas, its value, clone and firefox to Textarea loses current value when cloned

comment:6 Changed 4 years ago by dmethvin

  • Milestone changed from 1.3 to 1.4.3

comment:7 Changed 4 years ago by jitter

This is actually a firefox bug and it's know and sits there unfixed since 2004

 https://bugzilla.mozilla.org/show_bug.cgi?id=230307

comment:8 Changed 4 years ago by snover

  • Keywords firefox textarea value added; firefox, textarea, value, removed
  • Priority changed from major to low
  • Version changed from 1.2.6 to 1.4.3
  • Status changed from new to open
  • Milestone 1.4.3 deleted

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:9 Changed 4 years ago by addyosmani

#5524 is a duplicate of this ticket.

comment:10 Changed 4 years ago by dmethvin

  • Status changed from open to closed
  • Resolution set to patchwelcome

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 3 years ago by jakobhilden@…

Bug still exists in jQuery 1.6.2

Maybe this would be a solution?  https://github.com/spencertipping/jquery.fix.textarea-clone

comment:12 Changed 3 years ago by rwaldron

@jakobhilden@… see the previous comment by dmethvin

comment:13 Changed 3 years ago by rwaldron

#11136 is a duplicate of this ticket.

comment:14 Changed 2 years ago by Mark Wilden

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 21 months ago by Val Schuman <jquery@…>

Experiencing this bug in Chrome now. How come this ticket is closed?

comment:16 in reply to: ↑ 15 Changed 21 months ago by anonymous

Replying to Val Schuman <jquery@…>:

Experiencing this bug in Chrome now. How come this ticket is closed?

Same here.

comment:17 Changed 21 months ago by mikesherov

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 20 months ago by bugs.jquery.com@…

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 19 months ago by Anonymouse

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 17 months ago by anonymous

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 15 months ago by anonymous

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 months ago by cpaloia@…

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 9 months ago by jfeasel

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 9 months ago by dmethvin

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.

Note: See TracTickets for help on using tickets.