Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reapplying the "works with inputs without the form-control class", but in a working fashion #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/showErrors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ showErrorsModule.directive 'showErrors',
showSuccess = getShowSuccess options
trigger = getTrigger options

inputEl = el[0].querySelector '.form-control[name]'
inputEl = el[0].querySelector 'input[name],select[name],password[name],email[name],datetime[name],datetime-local[name],date[name],month[name],time[name],week[name],number[name],url[name],search[name],tel[name],color[name],textarea[name]'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't leave out the .form-control[name], because there may be other inputs (custom elements) that behave like form controls that you are missing now.

inputNgEl = angular.element inputEl
inputName = $interpolate(inputNgEl.attr('name') || '')(scope)
unless inputName
throw "show-errors element has no child input elements with a 'name' attribute and a 'form-control' class"
throw "show-errors element has no child input element with a 'name' attribute"

inputNgEl.bind trigger, ->
blurred = true
Expand Down
4 changes: 2 additions & 2 deletions src/showErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
options = scope.$eval(attrs.showErrors);
showSuccess = getShowSuccess(options);
trigger = getTrigger(options);
inputEl = el[0].querySelector('.form-control[name]');
inputEl = el[0].querySelector('input[name],select[name],password[name],email[name],datetime[name],datetime-local[name],date[name],month[name],time[name],week[name],number[name],url[name],search[name],tel[name],color[name],textarea[name]');
inputNgEl = angular.element(inputEl);
inputName = $interpolate(inputNgEl.attr('name') || '')(scope);
if (!inputName) {
throw "show-errors element has no child input elements with a 'name' attribute and a 'form-control' class";
throw "show-errors element has no child input element with a 'name' attribute";
}
inputNgEl.bind(trigger, function() {
blurred = true;
Expand Down
4 changes: 2 additions & 2 deletions src/showErrors.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/showErrors.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe 'showErrors', ->
$scope.$digest()
el

describe 'directive does not contain an input element with a form-control class and name attribute', ->
describe 'directive does not contain an input element with a "name" attribute', ->
it 'throws an exception', ->
expect( ->
$compile('<form name="userForm"><div class="form-group" show-errors><input type="text" name="firstName"></input></div></form>')($scope)
).toThrow "show-errors element has no child input elements with a 'name' attribute and a 'form-control' class"
$compile('<form name="userForm"><div class="form-group" show-errors><input type="text" ></input></div></form>')($scope)
).toThrow "show-errors element has no child input element with a 'name' attribute"

it "throws an exception if the element doesn't have the form-group or input-group class", ->
expect( ->
Expand Down
6 changes: 3 additions & 3 deletions test/showErrors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
$scope.$digest();
return el;
};
describe('directive does not contain an input element with a form-control class and name attribute', function() {
describe('directive does not contain an input element with a "name" attribute', function() {
return it('throws an exception', function() {
return expect(function() {
return $compile('<form name="userForm"><div class="form-group" show-errors><input type="text" name="firstName"></input></div></form>')($scope);
}).toThrow("show-errors element has no child input elements with a 'name' attribute and a 'form-control' class");
return $compile('<form name="userForm"><div class="form-group" show-errors><input type="text" ></input></div></form>')($scope);
}).toThrow("show-errors element has no child input element with a 'name' attribute");
});
});
it("throws an exception if the element doesn't have the form-group or input-group class", function() {
Expand Down