Link to home
Create AccountLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

Could you point why this HTML textarea is not actualized when changing the pictures since JS scripts shows it has changed?

Hi Experts

Could you point why this HTML textarea is not actualized when changing the pictures since JS scripts shows it has changed?

Accordingly to:

 User generated image
What occurs is:
User generated image
Page Code:
  <div class="modal fade" id="mMidiaEditar" tabindex="-1" role="dialog" aria-labelledby="mMidiaEditarLabel">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="mMidiaEditarLabel">Mídia</h4>
        </div>
        <div class="modal-body">
          {{ csrf_field() }}
          <input type='hidden' id='id'/>
          <div class='form-group'>
            <label for='tituloEditar'>Título:</label>
            <input type='text' class='form-control' id='tituloEditar' name='tituloEditar'/>
          </div>

<!--  --->
          <div class='form-group'>
            <label for='descricaoEditar'>Descrição X:</label>
            <textarea class='form-control' id='descricaoEditar' name='descricaoEditar' rows="5"></textarea>
          </div>
<!--  --->

          <div class='form-group'>
            <label for='tipoparticipanteEditar'>Perfil:</label>
            <select id='tipoparticipanteEditar' name='tipoparticipanteEditar' class='form-control'>
              <option value='0'>Para todos os perfis</option>
              @foreach($tipoparticipantes as $tipoparticipante)
                <option value="{{ $tipoparticipante->id}}">{{ $tipoparticipante->nome}}</option>
              @endforeach
            </select>
          </div>

        </div>

        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal"><i class="fas fa-times" aria-hidden="true"></i> Fechar</button>
          <button type="submit" class="btn btn-primary" onclick='hotsite.vitrine.atualizar();'><i class="fas fa-hdd" aria-hidden="true"></i> Salvar</button>
        </div>
      </div>
    </div>
  </div>

Open in new window


JS Code:
Vitrine.prototype.editarAdmin = function(id){
  $.ajax(
    {
        url: '/admin/vitrine/'+id+"/obter",
        method: "GET",
        error: function () {
          hotsite.openModalCustom("Erro", "Erro ao obter dados da vitrine.", "Entendi", "error");
        },
        success: function (data) {
          id = data.retorno.id;
          titulo = data.retorno.titulo;
          
    
          descricao = data.retorno.descricao;
          tipoparticipante_id = data.retorno.tipoparticipante_id;
          
          
          console.log(descricao);
          
          $('#id').val(id);
          $("#tituloEditar").val(titulo);
          $('#descricaoEditar').val(descricao);
          
          
          $('#tipoparticipanteEditar').val(tipoparticipante_id);
          //tinyMCE.get('descricaoEditar').setContent(descricao);
          hotsite.openModal('mMidiaEditar');
        }
    });
}

Open in new window



Thanks in advance.
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Hey Eduardo,

I think you'll find that a texarea doesn't have a val(), so you should use text() or html() instead:

$('#descricaoEditar').html(descricao);

Open in new window

Avatar of Eduardo Fuerte

ASKER

Hi Chris


Amazingly after your suggestion the content is actualized for the 1st time and then at every picture changing it's not actualized...
User generated image
OK. I would suggest you console.log the whole data response and see what you're getting back from your server:

success: function (data) {

    console.log(data.retorno);

    id = data.retorno.id;
    titulo = data.retorno.titulo;
    descricao = data.retorno.descricao;
    tipoparticipante_id = data.retorno.tipoparticipante_id;
    ...

Open in new window

It's been actualized.

Here is the result.

User generated image
          $('#id').val(id);
          $("#tituloEditar").val(titulo);
          $('#descricaoEditar').val(descricao);

Open in new window


Amazingly #tituloEditar is correctly actualized at the modal.
OK. This may be down to the plugin you're using for the editor (tinyMCE for example).

As a test, remove the code that sets up the editor and just leave a default <textarea> with no formatting. Once you've done that, test your edit buttons again to see if the basic textarea gets updated correctly.
Chris

Very good tip you gave me....

This part of the code had been comented by my, before:

 tinyMCE.get('descricaoEditar').setContent(descricao);

Open in new window


If I uncomment it, everything works out!....

Do you know what must it to be?
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Chris

Thank you for the help!
You're welcome Eduardo