I want my button enable when both forms are valid. My button is in the view at the level of the controller while a form is in a directive. What I have done does not work. I thought there might be some wrong syntax within my ng-disabled="" on my button. How do I accomplish this issue without some weird hack? Sorry, I'm new to Angularjs. Here are my codes. Cheers!!
index.html
<div ng-app="myApp" ng-controller="myCtrl">
<myform user="user1"></myform>
<myform user="user2"></myform>
<button ng-disabled="user1.formname.$invalid || user2.formname.$invalid">My Button</button>
</div>
my script
var app = angular.module('myApp', []);
app.controller('formCtrl', function($scope) {
$scope.user1 = {formname: "user1form" ,firstName: "John", lastName: "Doe"};
$scope.user2 = {formname: "user2form" ,firstName: "Lisa", lastName: "Smith"}
});
app.directive( 'datepickerform', function() {
return {
restrict: 'E',
scope: {
user : '='
},
templateUrl: 'myform.html',
link: function( scope, element, attrs ) {}
};
});
myform Directive Template :
<form name="user.formname" novalidate>
First Name:<br>
<input type="text" ng-model="user.firstName" required><br>
Last Name:<br>
<input type="text" ng-model="user.lastName" required>
</form>