After developing a hybrid app using Angular and Ionic, I encountered an issue where pressing the GO button or the arrow button on Android would submit the form even if it was not valid yet. Despite attempts to prevent this by detecting keypress events and using return:false;
, the problem persisted.
<form novalidate name="questionForm" id="questionForm" ng-submit="submit()">
<input name="question" ng-model="form.question" ng-minlength="10" required autofocus/>
<div id="answers">
<input ng-model="choice.choice" placeholder="Voeg antwoord toe" required ng-keypress="disableGo()" />
</div>
<button type="submit" ng-disabled="questionForm.$invalid" class="circle-btn btn-send ion-ios-paperplane"></button>
</form>
Function for Keypress:
$scope.disableGo = function () {
var code = (event.keyCode ? event.keyCode : event.which);
if ((code == 13) || (code == 10)) {
return false;
}
};