Skip to content

Commit 1f803a6

Browse files
committed
Allow input-group as well as form-group.
1 parent 40448d8 commit 1f803a6

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ angular.module('yourApp', ['ui.bootstrap.showErrors']);
3131
</form>
3232
```
3333

34+
3. If you want to avoid the extra bottom margin of `form-group`, you can use `input-group`.
35+
```html
36+
<form name="userForm">
37+
<div class="input-group" show-errors>
38+
<input type="text" name="firstName" ng-model="firstName" ng-required />
39+
</div>
40+
</form>
41+
```
42+
3443
Force Validity Check
3544
---
3645
By default this directive doesn't check the validity until the user tabs off the input element. However, there are times you want to show invalid form elements even if the user has not tabbed off. (e.g. before saving the form)
@@ -106,6 +115,7 @@ If you only want to show valid values on specific inputs, then you can pass in t
106115
</form>
107116
```
108117

118+
109119
Custom Trigger
110120
---
111121
By default, the validation is not performed until the `blur` event is trigger on the input

src/showErrors.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ 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+
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"
6262
linkFn
6363
}
6464
]

src/showErrors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
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 (!(elem.hasClass('form-group') || elem.hasClass('input-group'))) {
71+
throw "show-errors element does not have the 'form-group' or 'input-group' class";
7272
}
7373
return linkFn;
7474
}

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ describe 'showErrors', ->
3333
$compile('<form name="userForm"><div class="form-group" show-errors><input type="text" name="firstName"></input></div></form>')($scope)
3434
).toThrow "show-errors element has no child input elements with a 'name' attribute and a 'form-control' class"
3535

36-
it "throws an exception if the element doesn't have the form-group class", ->
36+
it "throws an exception if the element doesn't have the form-group or input-group class", ->
3737
expect( ->
3838
$compile('<div show-errors></div>')($scope)
39-
).toThrow "show-errors element does not have the 'form-group' class"
39+
).toThrow "show-errors element does not have the 'form-group' or 'input-group' class"
40+
41+
it "doesn't throw an exception if the element has the input-group class", ->
42+
expect( ->
43+
$compile('<form name="userForm"><div class="input-group" show-errors><input class="form-control" type="text" name="firstName"></input></div></form>')($scope)
44+
).not.toThrow()
4045

4146
it "throws an exception if the element isn't in a form tag", ->
4247
expect( ->

test/showErrors.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@
3535
}).toThrow("show-errors element has no child input elements with a 'name' attribute and a 'form-control' class");
3636
});
3737
});
38-
it("throws an exception if the element doesn't have the form-group class", function() {
38+
it("throws an exception if the element doesn't have the form-group or input-group class", function() {
3939
return expect(function() {
4040
return $compile('<div show-errors></div>')($scope);
41-
}).toThrow("show-errors element does not have the 'form-group' class");
41+
}).toThrow("show-errors element does not have the 'form-group' or 'input-group' class");
42+
});
43+
it("doesn't throw an exception if the element has the input-group class", function() {
44+
return expect(function() {
45+
return $compile('<form name="userForm"><div class="input-group" show-errors><input class="form-control" type="text" name="firstName"></input></div></form>')($scope);
46+
}).not.toThrow();
4247
});
4348
it("throws an exception if the element isn't in a form tag", function() {
4449
return expect(function() {

0 commit comments

Comments
 (0)