Delay ajaxsubmitbutton's submit for Elrte's textarea update to finish

The title might be somewhat confusing, I’ll elaborate.

My form looks something like this:

<!-- form begins -->

<?php echo CHtml::textArea('Page[new][0][text]', '', array('id'=>'Page_new_0_text'));?>

<?php echo CHtml::ajaxSubmitButton('Add text', CHtml::normalizeUrl(array('/page/addtext')), 

array('success'=>'addTextSuccess', 'beforeSend'=>'beforeAddText',), 

array('name'=>'ajaxTextSubmit')); ?>

and in the beforeAddText function, I have

function beforeAddText(){



(as seen on )

I’m using elrte-elfinder extension in a setup that adds multiple texts with an Elrte editor into a CGrid and then I submit everything at the end (meanwhile I hide the already added text in hidden fields etc.) with a page reload.

The twist is, that Elrte copies it’s content to the hidden textarea only on the onSubmit event, and since I’m using ajax, I have to do it manually in the beforeAddText function. So far so good.

The problem is, the ajax submit occurs before elrte finishes copying it’s contents to #Page_new_0_text, and the server receives an empty textarea.

If edit the text and submit again, the server receives the first version of the text, it is basically one version behind.

What this looks like:

Is there a way I could somehow delay the submission or work around this? I can’t change the way the submission occurs.

I solved this with a regular submit button and it’s click event.