Skip to content

Commit

Permalink
fix: don't override custom pattern (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored and web-padawan committed Nov 25, 2020
1 parent 4f6c3db commit ce30678
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 protected]',
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 ce30678

Please sign in to comment.