Skip to content

Commit

Permalink
Merge pull request #606 from vaadin/fix/required-invalid
Browse files Browse the repository at this point in the history
Bypass default value validation by checking if value has changed
  • Loading branch information
web-padawan authored Sep 24, 2018
2 parents 78287c9 + 04d4992 commit 8627c28
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/vaadin-date-picker-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,11 @@
this.__dispatchChange = true;
}
const inputValue = selectedDate && formatDate(Vaadin.DatePickerHelper._extractDateParts(selectedDate));
this.validate(inputValue);
this.value = this._formatISO(selectedDate);
const value = this._formatISO(selectedDate);
if (value !== this.value) {
this.validate(inputValue);
this.value = value;
}
this.__userInputOccurred = false;
this.__dispatchChange = false;
this._focusedDate = selectedDate;
Expand Down
2 changes: 1 addition & 1 deletion test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">

<link rel="import" href="../vaadin-date-picker.html">
Expand Down
2 changes: 1 addition & 1 deletion test/custom-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
<script src="common.js"></script>
Expand Down
16 changes: 8 additions & 8 deletions test/dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../vaadin-date-picker.html">
<link rel="import" href="not-animated-styles.html">
<script src="common.js"></script>
<script>
HTMLImports.whenReady(() => {
Polymer({
is: 'vaadin-date-picker-wrapper'
});
});
</script>
</head>

<body>
Expand All @@ -37,6 +30,13 @@
<template>
<vaadin-date-picker id="datepicker" label="foo"></vaadin-date-picker>
</template>
<script>
customElements.whenDefined('vaadin-date-picker').then(() => {
Polymer({
is: 'vaadin-date-picker-wrapper'
});
});
</script>
</dom-module>

<script>
Expand Down
26 changes: 25 additions & 1 deletion test/form-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="common.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">

Expand Down Expand Up @@ -37,6 +37,12 @@
</template>
</test-fixture>

<test-fixture id="datepicker-required">
<template>
<vaadin-date-picker required></vaadin-date-picker>
</template>
</test-fixture>

<test-fixture id="datepicker-in-form">
<template>
<iron-form>
Expand Down Expand Up @@ -218,6 +224,24 @@
});
});

describe('required', () => {
let datepicker;

beforeEach(done => {
datepicker = fixture('datepicker-required');
setTimeout(done);
});

it('should not be invalid without user interactions', () => {
expect(datepicker.invalid).to.be.false;
});

it('should be invalid after validate() if value is not set', () => {
datepicker.validate();
expect(datepicker.invalid).to.be.true;
});
});

describe('using as a field in an iron-form', () => {
var datepicker, ironForm;

Expand Down
2 changes: 1 addition & 1 deletion test/keyboard-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="common.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
Expand Down
2 changes: 1 addition & 1 deletion test/keyboard-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="common.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
Expand Down
2 changes: 1 addition & 1 deletion test/late-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="common.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">

Expand Down
2 changes: 1 addition & 1 deletion test/month-calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">

<link rel="import" href="../src/vaadin-month-calendar.html">
Expand Down
2 changes: 1 addition & 1 deletion test/overlay.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<script src="common.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">
Expand Down
2 changes: 1 addition & 1 deletion test/scroller.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="common.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">

Expand Down
2 changes: 1 addition & 1 deletion test/visual/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
document.write(`<link rel="import" href="../../theme/${theme}/vaadin-date-picker.html">`);

window.addEventListener('WebComponentsReady', function() {
setTimeout(function() {
customElements.whenDefined('vaadin-date-picker').then(() => {
window.ShadyDOM && window.ShadyDOM.flush(); // Force DOM composition
window.webComponentsAreReady = true; // Checked in gemini before capture callback
});
Expand Down
2 changes: 1 addition & 1 deletion test/wai-aria.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../test-fixture/test-fixture.html">

<link rel="import" href="../vaadin-date-picker.html">
Expand Down

0 comments on commit 8627c28

Please sign in to comment.