1
Good afternoon,
Today I am facing a rather strange bug in my application:
I have a textarea field where I type a body of email and just below it a button that when clicked obtains the content of the textarea, opens a modal and inserts the same content(value) inside the body of the modal.
The point is that some users are reporting that the button opens the modal but does not insert the value of the textarea within it.
While analyzing this issue I identified that it is not always that this occurs, when it gives problem, if you update the page the function tends to work.
When error occurs, when inspecting button click events I realize that it has been replaced by a Bootstrap JS function or simply no other function is replaced.
How can I make sure that doesn’t happen?
$('#btnPreviewEmail').click(function(){
var assunto = $('#txtAssuntoEmail').val();
var texto = CKEDITOR.instances['txtAreaCorpoDoEmail'].getData();
var namepage = 'Campanha Marketing Lojas Uno';
var landing = buscaLandingPorNamePage(namepage);
assunto = assunto.replace(/{{.FirstName}}/g, "Renoir dos Reis");
assunto = assunto.replace(/{{.DataHoje}}/g, '31/10/2016');
texto = texto.replace(/{{.FirstName}}/g, "Renoir dos Reis");
texto = texto.replace(/{{.Tracker}}/g, "");
texto = texto.replace(/{{.URL}}/g, landing);
texto = texto.replace(/{{.DataHoje}}/g, '31/10/2016');
$('#containerAssunto').html(assunto);
$('#containerPreview').html(texto);
});
Code of the button that opens the modal:
<button type="button" class="btn btn-warning" id="btnPreviewEmail" data-toggle="modal" data-target="#modalPreview">Pre-visualizar</button>
Modal:
You can put the HTML and code that fetches the value of the textarea?
– Sergio
What is the line that fetches the value? is the text or the subject?
– Sergio
@Sergio will both be searched
– Renoir Reis
But they both come from one
texarea
and have problems appearing in the modal?– Sergio
@Sergio, txtAreaCorpoDoEmail is a textarea of CKEDITOR, and the subject comes from an input type="text". Both do not appear in modal.
– Renoir Reis
And the code that actually opens the modal?
– bfavaretto
@bfavaretto entered the missing details.
– Renoir Reis
In the browser console (F12) some error appears?
– bfavaretto
@bfavaretto no :(.
– Renoir Reis
Everything indicates that you try to put content in the modal before the bootstrap leaves this modal ready. It may be that, it may not be. Try to put this code in a
$('#modalPreview').on('show.bs.modal', function (event) { /* COD AQUI */ })
instead of putting on the button click– bfavaretto
That button
btnPreviewEmail
is created dynamically? Tries to replace$('#btnPreviewEmail').click(function(){
for$('#btnPreviewEmail').on('click', function(){
– Pedro Camara Junior