I am using form in angular. When I click enter in any input field. It opens bsmodal.
Asked
Active
Viewed 677 times
0
-
Please post some code here. Refer this https://stackoverflow.com/help/how-to-ask – hrdkisback Oct 18 '19 at 10:04
-
Hello ! Some code would be nice, we can't help you like that… – Eudz Oct 18 '19 at 10:04
-
Well its a large file. StackOverflow will not allow to post it here. – Virendra Maheta Oct 18 '19 at 10:15
-
Maybe you have a button somewhere in the form which reacts to the 'enter' press and opens a modal? – igor_c Oct 18 '19 at 11:21
-
Does this answer your question? [HTML button to NOT submit form](https://stackoverflow.com/questions/2825856/html-button-to-not-submit-form) – Michael Freidgeim Jul 13 '23 at 22:21
3 Answers
1
You can stop the enter keydown directly in the form like this:
<form (keydown.enter)="$event.preventDefault()"></form>

Michael Desigaud
- 2,115
- 1
- 15
- 15
1
You might be able to fix this with a type="button"
on your button that opens your modal if it's inside a form element.
For reference:

Matthew Beck
- 451
- 5
- 19
0
you are using html form or some angular component to create form? You just have to stop the event You can use following code if you can use jq in your application
$('form input').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});

Parshant Dutta
- 450
- 1
- 4
- 12
-
-
import jquery and then you can use the exact code. import * as $ from 'jquery'; – Parshant Dutta Oct 18 '19 at 10:32