Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit button in Bootstrap form doesn't react on enter key

I have following Bootsrap form:

<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">×,
      </span>
    </button>
    <h4 class="modal-title">Datei speichern
    </h4>
  </div>
  <div class="modal-body">
    <p>Gib einen Dateinamen ein
    </p>
    <div class="form-group">
      <label class="input-label" for="project-bar-input">
      </label>
      <input type="text" class="form-control" id="project-bar-input">
    </div>
  </div>
  <div class="modal-footer">
    <button type="button" class="modal-cancel btn btn-default" data-dismiss="modal">Abbrechen
    </button>
    <button type="submit" class="modal-action btn btn-primary" data-dismiss="modal">Speichern
    </button>
  </div>
</div>

I try to catch an ENTER key event with

$( ".modal-content" ).find( "input#submit" ).click( function() {
    // submit
});

After reading:

Submit button not working in Bootstrap form

But it doesn't work. Why?

like image 921
Michael Avatar asked Dec 18 '22 17:12

Michael


1 Answers

$(function(){
  $('.modal-content').keypress(function(e){
    if(e.which == 13) {
      //dosomething
      alert('Enter pressed');
    }
  })
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">×,
      </span>
    </button>
    <h4 class="modal-title">Datei speichern
    </h4>
  </div>
  <div class="modal-body">
    <p>Gib einen Dateinamen ein
    </p>
    <div class="form-group">
      <label class="input-label" for="project-bar-input">
      </label>
      <input type="text" class="form-control" id="project-bar-input">
    </div>
  </div>
  <div class="modal-footer">
    <button type="button" class="modal-cancel btn btn-default" data-dismiss="modal">Abbrechen
    </button>
    <button type="submit" class="modal-action btn btn-primary" data-dismiss="modal">Speichern
    </button>
  </div>
</div>
like image 61
Shubham Khatri Avatar answered Dec 28 '22 06:12

Shubham Khatri