avoid submitting a form with barcode reader

2

Well I have the following form:

<form name="produto" method="post" action="cadastra.php">
   <input name="cod" type='text'>
   <button type='submit'>FINALIZAR</button>
</form>

Good Whenever I use the barcode reader it reads the code and submits the form, how do I avoid this? I just want him to read the code.

Is there any way to do this with jQuery?

    
asked by anonymous 17.05.2017 / 18:13

3 answers

4

Generally the bar code reader sends an enter after reading, you can set the reader to not execute enter, or you can detect action in the field and prevent the submit action from being called using the event.preventDefault ()

$('#cod').on('keypress',function(event){
  //Tecla 13 = Enter
  if(event.which == 13) {
    //cancela a ação padrão
    event.preventDefault();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formname="produto" method="post" action="cadastra.php">
   <input name="cod" type='text' id="cod">
   <button type='submit'>FINALIZAR</button>
</form>

Note that by clicking on the field and pressing enter the form is not sent but clicking the yes button.

    
17.05.2017 / 18:24
1

The bar code reader functions as a keyboard. He identifies the code, types and presses enter. You have to configure the player and disable the auto enter function.

    
17.05.2017 / 18:25
0

Use e.preventDefault (); According to the Jquery documentation; "If this method is called, the default event action will not fire."

Source: link

Example:

$('#meu_form').submit(function(e) { 
            e.preventDefault();
}); 
    
17.05.2017 / 18:26