Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Won't get changed form values from textareas... #18

Closed
ssuess opened this issue Apr 26, 2015 · 8 comments
Closed

Won't get changed form values from textareas... #18

ssuess opened this issue Apr 26, 2015 · 8 comments
Labels

Comments

@ssuess
Copy link

ssuess commented Apr 26, 2015

Hi, I have included this code on my page and it will print what is on the page wonderfully, with one exception: I have a couple of textareas on the page that I need to put text into and have that print with the page, but the values will not get printed. Whatever values those textareas hold at page load (one of them has default values) WILL print, but if I make any changes to the content of those textareas, those will NOT print, only the original copy will. I have checked that manuallyCopyFormValues is set to true, but no luck. Any ideas?

@ssuess
Copy link
Author

ssuess commented Apr 27, 2015

Well, I have a workaround, but it isn't pretty. By using jquery to force set the text (not val) of the textarea after entering text but before printing, the print code will now pick it up.

@CitizenOfRome
Copy link

Thanks, fixed!
manuallyCopyFormValues basically does the same thing, I had somehow missed adding support for textareas when I wrote it earlier

Please take a look and let me know if there are any issues still

@ssuess
Copy link
Author

ssuess commented Apr 27, 2015

Thanks!

@ssuess
Copy link
Author

ssuess commented Apr 28, 2015

actually, the new code doesn't work for me, I reverted back to my fix, which was essentially a separate function on the page that sets the values onblur:

jQuery(function() { jQuery("textarea.fromto").blur(function () { if(jQuery(this).val()!= "" ) { jQuery("textarea.fromto").text(jQuery(this).val()); } } });

@CitizenOfRome
Copy link

Hmm, that's odd, because that is essentially what we're doing here, only right before we insert the selected content into an iframe for printing rather than on-blur:

copy.find("textarea").each(function () {
   // Fix for https://github.com/DoersGuild/jQuery.print/issues/18#issuecomment-96451589
  var $field = $(this);
  $field.text($field.val());
});

@CitizenOfRome CitizenOfRome reopened this Apr 28, 2015
@ssuess
Copy link
Author

ssuess commented Apr 28, 2015

I don't understand either, it looks very similar. Let me go back through the code and see if anything sticks out...

@ssuess
Copy link
Author

ssuess commented Jun 8, 2015

I don't understand why you closed the other bug in relation to this one, they seem quite separate issues to me.

@KevinNBaer
Copy link

This added to the jQuery.print.js object will get the textareas cloned correctly.

(function (original) {
  jQuery.fn.clone = function () {
    var result = original.apply (this, arguments),
        my_textareas = this.find('textarea'),
        result_textareas = result.find('textarea'),
        my_selects = this.find('select'),
        result_selects = result.find('select');

    for (var i = 0, l = my_textareas.length; i < l; ++i)
      $(result_textareas[i]).val ($(my_textareas[i]).val());

    for (var i = 0, l = my_selects.length; i < l; ++i)
      $(result_selects[i]).val ($(my_selects[i]).val());

    return result;
  };
}) (jQuery.fn.clone);

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants