Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content in textareas set to use nicEdit not updating to reflect user changes

Accept my apologize because of my low English level

I use to load a page with jQuery and I use nicEdit in that page and I post datas to another page with jQuery. But it just send empty value instead of what user wrote in editor (if i define a default value for my text area, it just send the default value not the text wrote by user). What is the problem and what is the solution?

Thanks.


UPDATE After reading this related article and it's comments at end and reading other articles i found must use this way before submiting form :

nicEditors.findEditor('textarea_id').saveContent();

For this i use jquery to select any textarea and call .each() jquery function. For example :

$('textarea').each(function(){
   var IDOfThisTextArea =   $(this).attr('id');
   nicEditors.findEditor(IDOfThisTextArea).saveContent()
});

This work fine for textarea that created beforehand. But I have some textarea that created dynamically via jQuery that findEditor() function above didn't found those and not call saveContent() for those.

For this problem what you offer??????

tnx

like image 876
A.B.Developer Avatar asked Nov 05 '10 15:11

A.B.Developer


2 Answers

What about saving all instances like this before you submit the form

$('input[type=submit]').bind('click', function () {
    for(var i=0;i<nicEditors.nicInstances.length;i++){
        nicEditors.nicInstances[i].saveContent();
    }
});
like image 76
Gluip Avatar answered Nov 03 '22 19:11

Gluip


The basic answer for dynamically created elements is to use something like $('selector').on('click', function(...)) or whathaveyou to dynamically bind to the the triggering action, have that function body find any relevant .nice-wrapper textareas (via sensible selectors) as a jquery object $textareas, and prior to executing the submit

 $textareas.each(function(){ 
  nicEditors.findEditor(this.id).saveContent();
 });

which will then let you use some of the convenience methods like .serializeArray. Obviously, there are many different ways to solve this problem - e.g., perhaps you want to bind to the submit event of the form instead of to a click on a button - but I'd think many (most?) of the sensible solutions fall into the same general category.

like image 22
Carl Avatar answered Nov 03 '22 19:11

Carl