Jump to content

Recommended Posts

Hi,

 

I have a WYSIWG editor (called summernote) on my page. I also have a button #add-another which will clone the editor and add multiple.

 

The issue im having is that im unclear on how best to re-initialise the editors on a button click, as the page does not reload. Can anyone advise?

 

Should i somehow destroy the editors, then reinitialise? little confused.

 

I have the following so far, but not sure if im going down the right path, as its not working correctly.

 

Regards,

 

MoFish

<script>
$(document).ready(function() {
	function initialize() {
		$('.wysiwyg').summernote({
			height:150,
			minHeight: null,
			maxHeight: null
		});
	}

	initialize();

	$("#add-another").click(function(e) {
		e.preventDefault();
		$("#meta-clone").clone().appendTo("#meta-container");
		initialize();
	});
});
</script>
Link to comment
https://forums.phpfreaks.com/topic/301486-jquery-re-initialize-query-on-click/
Share on other sites

There is no need to re-initialize already existing editors, you only need to initialize the one in your new cloned area. You'd do that by finding the editor element in the clone then calling the summernote function on it.

 

$("#add-another").click(function(e) {
	e.preventDefault();
	var clone = $("#meta-clone").clone();
	clone.appendTo("#meta-container");

	clone.find('.wysiwyg').summernote({height: 150, minHeight: null, maxHeight: null});
});
On another note, if your currently cloning an existing already-initialized editor you should probably not be doing that. The clone should only have the editor placeholder element, then you initialize the editor after cloning.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.