Skip to content

Commit 88a0ad3

Browse files
committed
skip form group check option
1 parent 40448d8 commit 88a0ad3

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ If you only want to show valid values on specific inputs, then you can pass in t
106106
</form>
107107
```
108108

109+
Skip Form Group Check
110+
---
111+
If your HTML code doesn't have a form-group class, the form group check can be skipped:
112+
113+
```html
114+
<form name="userForm">
115+
<div show-errors="{ skipFormGroupCheck: true }">
116+
<input type="text" name="firstName" ng-model="firstName" ng-required />
117+
</div>
118+
</form>
119+
```
120+
109121
Custom Trigger
110122
---
111123
By default, the validation is not performed until the `blur` event is trigger on the input

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'
61-
throw "show-errors element does not have the 'form-group' class"
60+
if attrs['showErrors'].indexOf('skipFormGroupCheck') == -1
61+
unless elem.hasClass 'form-group'
62+
throw "show-errors element does not have the 'form-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')) {
71-
throw "show-errors element does not have the 'form-group' class";
70+
if (attrs['showErrors'].indexOf('skipFormGroupCheck') === -1) {
71+
if (!elem.hasClass('form-group')) {
72+
throw "show-errors element does not have the 'form-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
@@ -38,6 +38,11 @@ describe 'showErrors', ->
3838
$compile('<div show-errors></div>')($scope)
3939
).toThrow "show-errors element does not have the 'form-group' class"
4040

41+
it "doesn't throw an exception if the element doesn't have the form-group class but uses the skipFormGroupCheck option", ->
42+
expect( ->
43+
$compile('<form name="userForm"><div show-errors="{ skipFormGroupCheck: true }"><input class="form-control" type="text" name="firstName"></input></div></form>')($scope)
44+
).not.toThrow()
45+
4146
it "throws an exception if the element isn't in a form tag", ->
4247
expect( ->
4348
$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
@@ -40,6 +40,11 @@
4040
return $compile('<div show-errors></div>')($scope);
4141
}).toThrow("show-errors element does not have the 'form-group' class");
4242
});
43+
it("doesn't throw an exception if the element doesn't have the form-group class but uses the skipFormGroupCheck option", function() {
44+
return expect(function() {
45+
return $compile('<form name="userForm"><div show-errors="{ skipFormGroupCheck: true }"><input class="form-control" type="text" name="firstName"></input></div></form>')($scope);
46+
}).not.toThrow();
47+
});
4348
it("throws an exception if the element isn't in a form tag", function() {
4449
return expect(function() {
4550
return $compile('<div class="form-group" show-errors><input type="text" name="firstName"></input></div>')($scope);

0 commit comments

Comments
 (0)