Avatar of Eduardo Fuerte
Eduardo Fuerte
Flag 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:

 img002
What occurs is:
img003
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.
LaravelHTMLJavaScriptPHP

Avatar of undefined
Last Comment
Chris Stanyon

8/22/2022 - Mon
Chris Stanyon

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

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...
img004
Chris Stanyon

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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Eduardo Fuerte

ASKER
It's been actualized.

Here is the result.

img005
          $('#id').val(id);
          $("#tituloEditar").val(titulo);
          $('#descricaoEditar').val(descricao);

Open in new window


Amazingly #tituloEditar is correctly actualized at the modal.
Chris Stanyon

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.
Eduardo Fuerte

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Chris Stanyon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Eduardo Fuerte

ASKER
Chris

Thank you for the help!
Chris Stanyon

You're welcome Eduardo