Domanda

Ho un redattore jhquery jhtml wysiwyg in una forma e ho bisogno di aggiungere la sua uscita a una textarea manualmente.Il modulo viene inviato tramite Ajax.La funzione UpdateText è chiamata a afferrare cosa è nel div wysiwyg e posizionarlo in una textarea per abilitare Ajax di inviarlo.Sto usando il callback ajaxform "beforeSubmit" per sparare questa funzione.

//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;
}; 
.

Questo non funziona al primo invio ... devi fare clic su Invia due volte prima di aggiornare in realtà gli incendi.Qualcuno ha qualche idea?

Grazie,

È stato utile?

Soluzione

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;
}; 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top