Skip to content

Commit a7b79f5

Browse files
committed
Merge branch 'lukaselmer-master'
2 parents 5dc3c7f + 83fb79e commit a7b79f5

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ If you only want to show valid values on specific inputs, then you can pass in t
115115
</form>
116116
```
117117

118+
Skip Form Group Check
119+
---
120+
If your HTML code doesn't have a form-group class, the form group check can be skipped:
121+
122+
```html
123+
<form name="userForm">
124+
<div show-errors="{ skipFormGroupCheck: true }">
125+
<input type="text" name="firstName" ng-model="firstName" ng-required />
126+
</div>
127+
</form>
128+
```
118129

119130
Custom Trigger
120131
---

src/showErrors.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ showErrorsModule.directive 'showErrors',
5757
restrict: 'A'
5858
require: '^form'
5959
compile: (elem, attrs) ->
60-
unless elem.hasClass('form-group') or elem.hasClass('input-group')
61-
throw "show-errors element does not have the 'form-group' or 'input-group' class"
60+
if attrs['showErrors'].indexOf('skipFormGroupCheck') == -1
61+
unless elem.hasClass('form-group') or elem.hasClass('input-group')
62+
throw "show-errors element does not have the 'form-group' or 'input-group' class"
6263
linkFn
6364
}
6465
]

src/showErrors.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
restrict: 'A',
6868
require: '^form',
6969
compile: function(elem, attrs) {
70-
if (!(elem.hasClass('form-group') || elem.hasClass('input-group'))) {
71-
throw "show-errors element does not have the 'form-group' or 'input-group' class";
70+
if (attrs['showErrors'].indexOf('skipFormGroupCheck') === -1) {
71+
if (!(elem.hasClass('form-group') || elem.hasClass('input-group'))) {
72+
throw "show-errors element does not have the 'form-group' or 'input-group' class";
73+
}
7274
}
7375
return linkFn;
7476
}

src/showErrors.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/showErrors.spec.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ describe 'showErrors', ->
4343
$compile('<form name="userForm"><div class="input-group" show-errors><input class="form-control" type="text" name="firstName"></input></div></form>')($scope)
4444
).not.toThrow()
4545

46+
it "doesn't throw an exception if the element doesn't have the form-group class but uses the skipFormGroupCheck option", ->
47+
expect( ->
48+
$compile('<form name="userForm"><div show-errors="{ skipFormGroupCheck: true }"><input class="form-control" type="text" name="firstName"></input></div></form>')($scope)
49+
).not.toThrow()
50+
4651
it "throws an exception if the element isn't in a form tag", ->
4752
expect( ->
4853
$compile('<div class="form-group" show-errors><input type="text" name="firstName"></input></div>')($scope)

test/showErrors.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
return $compile('<form name="userForm"><div class="input-group" show-errors><input class="form-control" type="text" name="firstName"></input></div></form>')($scope);
4646
}).not.toThrow();
4747
});
48+
it("doesn't throw an exception if the element doesn't have the form-group class but uses the skipFormGroupCheck option", function() {
49+
return expect(function() {
50+
return $compile('<form name="userForm"><div show-errors="{ skipFormGroupCheck: true }"><input class="form-control" type="text" name="firstName"></input></div></form>')($scope);
51+
}).not.toThrow();
52+
});
4853
it("throws an exception if the element isn't in a form tag", function() {
4954
return expect(function() {
5055
return $compile('<div class="form-group" show-errors><input type="text" name="firstName"></input></div>')($scope);

0 commit comments

Comments
 (0)