Skip to content

Commit

Permalink
fix: don't override custom pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Oct 5, 2020
1 parent d5ee187 commit af19d09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vaadin-email-field.html
Expand Up @@ -89,7 +89,7 @@
/** @protected */
_createConstraintsObserver() {
// NOTE: pattern needs to be set before constraints observer is initialized
this.pattern = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$';
this.pattern = this.pattern || '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$';

super._createConstraintsObserver();
}
Expand Down
10 changes: 10 additions & 0 deletions test/email-field.html
Expand Up @@ -18,6 +18,12 @@
</template>
</test-fixture>

<test-fixture id="custom-pattern">
<template>
<vaadin-email-field pattern=".+@example\.com"></vaadin-email-field>
</template>
</test-fixture>

<script>
const validAddresses = [
'email@example.com',
Expand Down Expand Up @@ -59,6 +65,10 @@
expect(input.type).to.equal('email');
});

it('should not override custom pattern', () => {
expect(fixture('custom-pattern').pattern).to.equal('.+@example\\.com');
});

describe('validation', () => {
describe('valid email addresses', () => {
validAddresses.map(address => {
Expand Down

0 comments on commit af19d09

Please sign in to comment.