diff --git a/lib/ui/validation/adapter-bootstrap.js b/lib/ui/validation/adapter-bootstrap.js index 871bde6e..3a7cc245 100644 --- a/lib/ui/validation/adapter-bootstrap.js +++ b/lib/ui/validation/adapter-bootstrap.js @@ -14,8 +14,7 @@ NAVBAR: 'navbar-fixed-top' }, SELECTORS: { - CONTAINER: 'container-id', - DATA_CONTAINER: 'data-container-id' + CONTAINER: 'container-id' }, CONTROLLER: '$avValContainerController' }); @@ -36,7 +35,7 @@ element.parents(AV_BOOTSTRAP_ADAPTER.CLASSES.FORM_GROUP).removeClass(AV_BOOTSTRAP_ADAPTER.CLASSES.ERROR); }, - message: function(element, ngModel) { + message: function(element, ngModel, attrs) { var selector = [ '.', @@ -45,10 +44,9 @@ var $el = $(element); - var target = $el.attr(AV_BOOTSTRAP_ADAPTER.SELECTORS.CONTAINER); - target = target || $el.attr(AV_BOOTSTRAP_ADAPTER.SELECTORS.DATA_CONTAINER); - // default to siblings - target = target ? $('#' + target) : $el.siblings(selector); + var targetId = attrs[attrs.$normalize(AV_BOOTSTRAP_ADAPTER.SELECTORS.CONTAINER)]; + + var target = targetId ? $('#' + targetId) : $el.siblings(selector); if(target.length === 0) { $log.warn('avValBootstrapAdapter could not find validation container for {0}', [element]); diff --git a/lib/ui/validation/adapter.js b/lib/ui/validation/adapter.js index 62dd11c5..ecd03a70 100644 --- a/lib/ui/validation/adapter.js +++ b/lib/ui/validation/adapter.js @@ -33,8 +33,8 @@ this.adapter.reset(element); }; - proto.message = function(element, ngModel) { - this.adapter.message(element, ngModel); + proto.message = function(element, ngModel, attrs) { + this.adapter.message(element, ngModel, attrs); }, proto.scroll = function(form) { diff --git a/lib/ui/validation/field.js b/lib/ui/validation/field.js index 9da06cb2..7c4e29a6 100644 --- a/lib/ui/validation/field.js +++ b/lib/ui/validation/field.js @@ -68,7 +68,7 @@ this.updateView = function() { if(this.ngModel.$dirty || $scope.avValShow) { avValAdapter.element($element, this.ngModel, this.ngModel.avResults.isValid); - avValAdapter.message($element, this.ngModel); + avValAdapter.message($element, this.ngModel, $attrs); } }; @@ -143,7 +143,7 @@ var violations = this.ngModel.avResults.violations; violations.splice(0, violations.length); - avValAdapter.message($element, this.ngModel); + avValAdapter.message($element, this.ngModel, $attrs); avValAdapter.reset($element); }; diff --git a/lib/ui/validation/form.js b/lib/ui/validation/form.js index 6a4a9529..cef50f07 100644 --- a/lib/ui/validation/form.js +++ b/lib/ui/validation/form.js @@ -125,7 +125,7 @@ // fields inside the form would inherit this behavior. avForm.avValOn = iAttrs.avValOn || null; avForm.avValDebounce = iAttrs.avValDebounce || null; - avForm.avValShow = scope.$eval(iAttrs.avValShow) || null; + avForm.avValShow = iAttrs.avValShow || null; // Allows fields to update with invalid data for dirty form saving avForm.avValInvalid = iAttrs.avValInvalid || false; diff --git a/lib/ui/validation/tests/form-spec.js b/lib/ui/validation/tests/form-spec.js index 674c72c3..3666f5e7 100644 --- a/lib/ui/validation/tests/form-spec.js +++ b/lib/ui/validation/tests/form-spec.js @@ -120,40 +120,38 @@ describe('avForm', function() { expect(formGroup.hasClass('has-error')).toBeTruthy(); }); - it('should not immediately create an error if avValShow variable is false', function() { + it('should validate inside ng-repeat', function() { var template = '' + - '
' + - '
' + - '' + + ''+ + '
' + + '' + '

' + '
' + ''; - availity.mock.$scope.demo.showError = false; - + availity.mock.$scope.demo.names = ["charizard", "blastoise", "venasaur", "mewtwo", "mew", "pikachu", "m"]; $el = availity.mock.compileDirective(template); - availity.mock.$scope.$digest(); - - var formGroup = $('#showOnLoadFormGroup'); - expect(formGroup.hasClass('has-error')).toBeFalsy(); + var invalidName = $('#name-6'); + expect(invalidName.hasClass('ng-invalid')).toBeTruthy(); + var validName = $('#name-5'); + expect(validName.hasClass('ng-invalid')).toBeFalsy(); }); - it('should immediately create an error if avValShow variable is true', function() { + it('should validate inside ng-repeat with container-id', function() { var template = '' + - '
' + - '
' + - '' + - '

' + + ''+ + '
' + + '' + + '

' + '
' + ''; - availity.mock.$scope.demo.showError = true; - + availity.mock.$scope.demo.names = ["charizard", "blastoise", "venasaur", "mewtwo", "mew", "pikachu", "m"]; $el = availity.mock.compileDirective(template); - availity.mock.$scope.$digest(); - - var formGroup = $('#showOnLoadFormGroup'); - expect(formGroup.hasClass('has-error')).toBeTruthy(); + var invalidName = $('#name-6'); + expect(invalidName.hasClass('ng-invalid')).toBeTruthy(); + var validName = $('#name-5'); + expect(validName.hasClass('ng-invalid')).toBeFalsy(); }); describe('submit', function() {