複数の送信ボタンがあるフォームがあります。
<form name="myForm" customSubmit>
<input type="text" ng-minlength="2">
<button type="submit" ng-click="foo1()"></button>
<button type="submit" ng-click="foo2()"></button>
</form>
およびディレクティブ:
angular.module('customSubmit', [])
.directive('customSubmit', function() {
return {
require: '^form',
scope: {
submit: '&'
},
link: function(scope, element, attrs, form) {
element.on('submit', function() {
scope.$apply(function() {
form.$submitted = true;
if (form.$valid) {
return scope.submit();
}
});
});
}
};
});
私の目標は、複数の送信ボタンを使用して、有効な場合にのみフォームを送信することです (つまり、フォームで ng-submit ディレクティブを使用できません)。上記のコードは機能しません。それを行う正しい方法は何ですか?それは可能ですか?