Angular: Empty Fiddle
http://angularjs.org/
by jeberly
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<form name="myform">
<input ng-model="name" class="add-validations">
<button ng-click="submit(name)" ng-disabled="myform.$invalid">
this button should be inactive
</button>
</form>
<form name="myform2">
<input ng-model="name2" required="required">
<button ng-click="submit(name2)" ng-disabled="myform2.$invalid">
this button is active until text input
</button>
</form>
</div>
JavaScript
var myApp = angular.module('myApp', ['customFieldDirectives']);
angular.module('customFieldDirectives', []).directive('addValidations', function() {
return {
restrict: 'C',
link: function(scope, element, attrs) {
if (true) {
console.log('in here');
//element.attr('required', true);
}
},
compile: function compile(tElement, tAttrs, transclude) {
return {
post: function postLink(scope, iElement, iAttrs, controller) {
iElement.attr('required', true);
console.log(iElement);
}
}
}
};
});
function MyCtrl($scope) {
$scope.submit = function(name) {
alert(name);
}
}