Hi,

I'm trying to create a directive that does some validation and displays a 
custom error message.  I'm using boostrap.angular.validation, so supposedly 
I just have to do something with the $validator.  Below is my directive.  
If year is not found, I want to highlight the DateCompletedCSA field and 
display a custom error.  I've searched all over for doc on how to find 
this, but have ran into a wall:

WellnessReimbursementsApp.directive('dateValidator', function () {

return {

restrict: 'A',

require: 'ngModel',

link: function (scope, element, attrs, controller) {


element.on('mouseout', function (event) { 

if (scope.member.request.DateCompleted != null) {

// 2. Check the year against the allowed reimbursement years:

//var dateCompletedYear = scope.member.request.DateCompleted.getFullYear();

console.log(scope.member.request.DateCompleted);

var dateCompletedYear = '2012';

var foundValidYear = false;

$.each(scope.member.AllowedReimbursementYears, function (index, value) {

if (dateCompletedYear == value) {

foundValidYear = true;

console.log("found valid year");

return;

}

});

if (!foundValidYear) {

// can get it to alert, just not sure how to show custom message and flag 
correctly

//alert('bad year ' + dateCompletedYear);

// element.parent.find('.bs-invalid-msg').html(dateCompletedYear + ' year 
not allowed.');

//element.parent.find('.bs-invalid-msg').show();

//controller.$setValidity('DateCompletedCSA', false);

// controller.$validators.date = false;

//controller

//scope.$digest();

//scope.WellnessReimbursmentForm.DateCompletedCSA.$showValidation();

controller.$parsers.unshift(function (value) {

});

}

}

});

}

}

-- 
You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to