Skip to content

Commit

Permalink
fix(validity): validate when auro-select loses focus
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjones243 committed Dec 16, 2022
1 parent beefb56 commit ac77c63
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/auro-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,24 @@ class AuroSelect extends LitElement {
*/
validate() {
// Validate only if noValidate is not true and the input does not have focus
if (this.hasAttribute('error')) {
this.validity = 'customError';
this.setCustomValidity = this.error;
} else if (this.value !== undefined && !this.noValidate) {
this.validity = 'valid';
this.setCustomValidity = '';

/**
* Only validate once we interact with the datepicker
* this.value === undefined is the initial state pre-interaction.
*
* The validityState definitions are located at https://developer.mozilla.org/en-US/docs/Web/API/ValidityState.
*/
if ((!this.value || this.value.length === 0) && this.required) {
this.validity = 'valueMissing';
this.setCustomValidity = this.setCustomValidityValueMissing;
if (!this.contains(document.activeElement)) {
if (this.hasAttribute('error')) {
this.validity = 'customError';
this.setCustomValidity = this.error;
} else if (this.value !== undefined && !this.noValidate) {
this.validity = 'valid';
this.setCustomValidity = '';

/**
* Only validate once we interact with the datepicker
* this.value === undefined is the initial state pre-interaction.
*
* The validityState definitions are located at https://developer.mozilla.org/en-US/docs/Web/API/ValidityState.
*/
if ((!this.value || this.value.length === 0) && this.required) {
this.validity = 'valueMissing';
this.setCustomValidity = this.setCustomValidityValueMissing;
}
}
}

Expand Down

0 comments on commit ac77c63

Please sign in to comment.