Prevent form submission on enter key

后端 未结 15 1258
夕颜
夕颜 2020-12-05 06:24

How can I prevent the enter key from submitting the form in angular?

Is there a way to catch the 13 key and disable it or set the form as invalid unless submitting f

15条回答
  •  自闭症患者
    2020-12-05 06:35

    You can catch the default form submit in your controller using ng-submit on the form tag and it will prevent a submit:

    http://docs.angularjs.org/api/ng.directive:ngSubmit

    alternatively, if you really wanted to catch the key events, there are also directives for that which pass an event you can call stop:

    http://docs.angularjs.org/api/ng.directive:ngKeyup

提交回复
热议问题