Pregunta

Tengo un editor JQuery JHTML WYSIWYG en un formulario y necesito agregar su salida a un TextarArea manualmente.El formulario se está enviando a través de AJAX.La función de actualización se llama para agarrar qué hay en el DIV de WYSIWYG y colóquelo en un TextArea para permitir que Ajax lo envíe.Estoy usando la devolución de llamada de AJAXFORF "BEFORESUMIT" para disparar esta función.

//For Ajax Form
$('#addFaci').ajaxForm({
        beforeSubmit: updateText,
        success: function(response) {
            eval(response);
        }
});

function updateText(formData, jqForm, options){
    var save = '#detail';
    $(save).val($(save).htmlarea("toHtmlString"));
    return true;
}; 

Esto no funciona en el primer envío ... debe hacer clic en Enviar dos veces antes de que UpdateText realmente se incendien.¿Alguien tiene alguna idea?

gracias,

¿Fue útil?

Solución

When you hit submit this is what happens:

  1. Form data is being collected
  2. beforeSubmit fires, and the collected form data is being passed as the first parameter
  3. You're changing the value of textarea, but it's too late, because data has been already collected

Instead of changing textarea's value you should modify formData object.

UPD. Try this:

for (var i in formData) {
  if (formData[i].name == '...name of your textarea here...') {
    formData[i].value = ...wysiwyg's html...
  }    
}

Even easier, remove the hidden textarea and use this:

function updateText(formData, jqForm, options) {
    formData.push({name: 'textarea_name', value: .... })
    return true;
}; 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top