We help IT Professionals succeed at work.
Get Started

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?

Eduardo Fuerte
on
86 Views
Last Modified: 2020-02-26
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

Open in new window



Thanks in advance.
Comment
Watch Question
Developer and Analyst
Commented:
This problem has been solved!
Unlock 1 Answer and 17 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE