Skip to content

Commit 2ef6305

Browse files
committed
Added in check to see if multiple is defined, as per HTML5 spec for input. It returns a string, not an array, but should be included as valid HTML and validated by Angular. angular#4549
1 parent 5e80c4f commit 2ef6305

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/ng/directive/input.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,15 @@ function urlInputType(scope, element, attr, ctrl, $sniffer, $browser) {
606606
function emailInputType(scope, element, attr, ctrl, $sniffer, $browser) {
607607
textInputType(scope, element, attr, ctrl, $sniffer, $browser);
608608

609+
var isMultiple = attr.multiple;
610+
var isNgList = attr.ngList;
611+
609612
var emailValidator = function(value) {
610613
var testedValid;
611-
if (isArray(value)) {
614+
if (isString(isNgList) && isArray(value)) {
612615
testedValid = every(value, function(val){return EMAIL_REGEXP.test(val)})
616+
} else if (isMultiple && isString(value)) {
617+
testedValid = every(value.split(','), function(val){return EMAIL_REGEXP.test(trim(val));});
613618
} else {
614619
testedValid = EMAIL_REGEXP.test(value)
615620
}

test/ng/directive/inputSpec.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,32 @@ describe('input', function() {
785785
expect(inputElm).toBeInvalid();
786786
expect(widget.$error.email).toBeTruthy();
787787
});
788-
});
788+
it('when used with multiple (default separator)', function() {
789+
compileInput('<input multiple type="email" ng-model="email" name="alias" />');
790+
791+
var widget = scope.form.alias;
792+
changeInputValueTo('[email protected]');
793+
expect(scope.email).toEqual('[email protected]');
794+
expect(inputElm).toBeValid();
795+
expect(widget.$error.email).toBe(false);
796+
797+
changeInputValueTo('[email protected], [email protected]');
798+
expect(scope.email).toEqual('[email protected],[email protected]');
799+
expect(inputElm).toBeValid();
800+
expect(widget.$error.email).toBe(false);
789801

802+
changeInputValueTo('[email protected]; [email protected]');
803+
expect(scope.email).toBeUndefined;
804+
expect(inputElm).toBeInvalid();
805+
expect(widget.$error.email).toBeTruthy();
806+
807+
808+
changeInputValueTo('invalid@');
809+
expect(scope.email).toBeUndefined();
810+
expect(inputElm).toBeInvalid();
811+
expect(widget.$error.email).toBeTruthy();
812+
});
813+
});
790814

791815
describe('EMAIL_REGEXP', function(){
792816
it('should validate email', function() {

0 commit comments

Comments
 (0)