Yesterday, I upgraded from angular 1.0.8 to angular 1.2.2 and encountered a problem where the $render function in the directive below is no longer firing, despite fixing other issues that arose.
Has anyone else experienced this issue before?
directive('validFile', function (utils, $filter) {
return {
require: 'ngModel',
link: function (scope, el, attrs, ngModel) {
if(utils.isMobileAgent())
return;
var form = el.parents().find('form');
ngModel.$render = function () {
debugger;
if(form.hasClass('ng-pristine'))
return;
if(el.val() && el.val().length > 0){
ngModel.$setViewValue(el.val());
}
if(el.hasClass('ng-invalid')){
el.parent().addClass('ng-invalid').addClass('ng-invalid-required');
ngModel.$setValidity(attrs.name, false);
ngModel.$setPristine(attrs.name, false);
scope.fileMsg = $filter('translate')('PLEASESELECT') + ' ' + $filter('translate')(attrs.name);
// scope.layout.showFileError = true;
}
else{
el.parent().removeClass('ng-invalid').removeClass('ng-invalid-required').addClass('ng-valid');
ngModel.$setValidity(attrs.name, true);
}
};
el.bind('mouseover', function(){
if(form.hasClass('ng-dirty') && el.parent().hasClass('ng-invalid'))
el.removeClass('ng-pristine');
});
el.bind('mouseleave', function(){
if(el.val() && el.val().length > 0){
el.addClass('ng-pristine');
}
})
el.bind('change', function () {
scope.$apply(function () {
ngModel.$render();
});
});
form.bind('change', function () {
scope.$apply(function () {
ngModel.$render();
});
});
}
};
});
markup:
<input type="file" data-ng-model='model.formData.resume' name="resume" data-valid-file data-my-validate data-value-required="true">