Skip to content

Commit 191b89e

Browse files
fix(chapter-9): Remove modification of type attribute on buttons
This is not allowed by certain browsers who shall not be named, and so neither by jQuery.
1 parent bb414c0 commit 191b89e

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

1820EN_09_Code/02_button_directive/directive.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ angular.module('button-directive', [])
55
restrict: 'E',
66
compile: function(element, attributes) {
77
element.addClass('btn');
8-
if ( attributes.type === 'submit' || attributes.type === "primary" ) {
9-
attributes.$set('type','submit');
8+
if ( attributes.type === 'submit' ) {
109
element.addClass('btn-primary');
11-
} else if ( angular.isDefined(attributes.type) && attributes.type !== 'reset' ) {
12-
element.addClass('btn-' + attributes.type);
13-
attributes.$set('type', 'button');
1410
}
1511
if ( attributes.size ) {
1612
element.addClass('btn-' + attributes.size);

1820EN_09_Code/02_button_directive/directive.spec.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ describe('button directive', function () {
2121
expect(element.hasClass('btn-large')).toBe(true);
2222
});
2323

24-
it('set button type and CSS classes correctly', function() {
24+
it('adds primary class to submit buttons', function() {
2525
var element = $compile('<button type="submit"></button>')($rootScope);
2626
expect(element.hasClass('btn-primary')).toBe(true);
27-
expect(element.attr('type')).toBe('submit');
28-
29-
element = $compile('<button type="reset"></button>')($rootScope);
30-
expect(element.attr('type')).toBe('reset');
31-
32-
element = $compile('<button type="warning"> </button>')($rootScope);
33-
expect(element.hasClass('btn-warning')).toBe(true);
34-
expect(element.attr('type')).toBe('button');
3527
});
3628

3729
});

0 commit comments

Comments
 (0)