troubleshooting Question

Could you point what must to be adjusted at this view code to avoid the form beeing submited if the modal's textbox is empty?

Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil asked on
LaraveljQueryPHP
17 Comments1 Solution88 ViewsLast Modified:
Hi Experts


Could you point what must to be adjusted at this view's code to avoid the form beeing submited if the modal's textbox is empty?

Accordingly with:


<?

<div class='row'>
    <br/>
    <div class="well well-lg text-center">
        <h1>Fotos</h1>
    </div>
</div>

<input type='hidden' id='pagina' value='1'/>

<div class="container">
    <div class="row">
    
          <!--div class="panel panel-primary"-->
          <div class="panel panel-default">
          
            <div class="panel-body">
                <div class=" col-md-12 col-sm-12"> 
                      <div class='row'>
                      
                         <div class="col-sm-12 col-md-6">
                          <div class="btn-group" role="group">
                            <button type="button" class="btn btn-primary" onclick="Xxxxx.vitrine.minhasfotos();">
                              <i class="fas fa-video" aria-hidden="true"></i> Minhas Fotos
                            </button>
                          </div>
                        </div>
                        
                         <div class="col-sm-12 col-md-3">
                          <div class="btn-group" role="group">
                            <button type="button" class="btn btn-primary" onclick="Xxxxx.vitrine.todasfotos();">
                              <i class="fas fa-video" aria-hidden="true"></i> Todas as Fotos
                            </button>
                          </div>
                        </div>
                          
                         <div class="col-sm-12 col-md-3">
                          <div class="btn-group" role="group">
                            <button type="button" class="btn btn-primary" onclick="Xxxxx.vitrine.novo();">
                              <i class="fas fa-video" aria-hidden="true"></i> Enviar Foto
                            </button>
                          </div>
                        </div>
                          
                      </div>  
                      
                  </div>
            </div>
        </div>
    </div>
</div>

<div class='row' id="lista"></div>

  <div class='row'>
    <div id="midiaList">
      @include('vitrines.fotos')
    </div>
  </div>


<!-- Modal -->
<div class="modal fade" id="mEditor" tabindex="-1" role="dialog" aria-labelledby="mEditorLabel">
  <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="mEditorLabel">Nova Foto</h4>
      </div>
      <div class="modal-body row">
            <input type='hidden' value="0" id='id' name='id'>

            <div class='col-md-7'>
  
                <div class='col-md-12 form-group'>
                    <label for='title'>Título</label>
                    <input type='text' id='title' name='title' class='form-control'/>
                </div>

                <div class='col-md-12 form-group'>
                    <label for='description'>Descrição</label>
                    <input type='text' id='description' name='description' class='form-control'/>
                </div>
                
            </div>

            <div id='box-video' class='col-md-5 text-center'>
            
                <img id='srcVitrine' src=''>
                

                <div class='col-md-12 form-group'>
                    <label for='titulo'>URL (Foto/ Imagem):</label>
                    <div class="input-group">
                        <input type='text' id='url' name='url' disabled class='form-control'/>
                        <span class="input-group-btn">
                            <button class="btn btn-primary" type="button" onclick='Xxxxx.vitrine.subirVideo();'><i class="fa fa-camera"></i></button>
                        </span>
                        <input type='file' id='file' name='file' style='display:none;'/>
                    </div>
                </div>
            </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="button"  id="btnSubmit" class="btn btn-primary" onclick="Xxxxx.vitrine.salvar();"><i class="fas fa-hdd" aria-hidden="true"></i> Salvar</button>
      
	  
	  </div>
    </div>
   
  </div>
</div>

<script>
  var jqXHRData;
  $(document).ready(function() {
    
    var pars = {
        _token:$('input[name="_token"]').val()
    };

       var resultImageUpload = function (data) {
        if (!data.result.erro) {
            localizacao = data.result.retorno.localizacao;
            $('#url').val(localizacao);
            
            $('#srcVitrine').attr('src', localizacao);


            return false;
        } else {
          xxx.openModalCustom("Erro",'Erro ao subir vídeo.', "Entendi", "error");
          return false;
        }
        else
        {

// ---- ADJUST ---This function is called but even returning false the form is submited with success 
            $(function() {  
                $('#btnSubmit').click(function() {  
                    var txt = $('#title');  
                    if (txt.val() != null && txt.val() != '') {  
                        alert('you entered text ' + txt.val())  
                    } else {  
                        alert('Please enter text')  
                        return false;   
                    }  
                })  
            });  
       
        }
    
    };

    var failImageUpload = function (data) {
          if (data.files[0].error) {
              Xxxxx.openModalCustom("Erro",'Erro ao subir vídeo.', "Entendi", "error");
              return false;
          }
    };

    Xxxxx.InitFileUpload("file", "/vitrine/salvarVitrine", pars, resultImageUpload, failImageUpload);

   // Limpa a Modal
   $(".modal").on("hidden.bs.modal", function(){
        $(".modal-body input").val("")
    });


    $("#file").change(function () {
        if (jqXHRData) {
            jqXHRData.submit();
        }
        return false;
    });
  })
</script>
@endsection


Thanks in advance.
ASKER CERTIFIED SOLUTION
Eduardo Fuerte
Developer and Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros