Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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();
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top