Possible bug input number in firefox

Asked

Viewed 103 times

3

I was developing a calculation where I used a number field and a text field, where in the number field the user would inform the amount of an item and the text field would give the value of the calculated item. In some tests performed, when the number field is modified via the field arrows, when resetting the form, the value of the number field is not discarded. Such error occurs only in firefox and only when selecting the value one(1). If you type the number via keyboard and reset the form the error does not happen. In this link from JSFIDDLE it is possible to check the error. Is there any way to fix this?

  • I selected the value 1 and the form has been reset correctly. I am using Firefox 32 by Fedora 20.

  • Hello @Oeslei, repeat this procedure twice. The text field does not show the calculation.

  • To reproduce the problem: up arrow, check, up arrow.

  • The problem does occur.

1 answer

4


Apparently, by calling the method reset form the value of the numeric field is not considered "changed", so that when you pass it again to 1 through the arrows, it does not fire the event onchange.

I don’t know why this happens, but a workaround would set this value to zero before calling reset:

$(".ve").on("click", function(){ 
   alert('res');
   $("#quantidade").val(0); // O valor não será mais `1`
   $(this).parent().find('form')[0].reset();
});

Example. P.S. If you reset the form and use the arrow down, the second field will show NaN. It would be interesting to test by isNaN in the change to prevent this.

  • 1

    Hello @mgibsonbr, The solution worked perfectly, and to prevent the appearance of NaN added the check: if( $("#quantidade").val() >= '1' ). Thanks for the help once again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.