Skip to content

Instantly share code, notes, and snippets.

@rtmalone
Created December 10, 2021 20:33
Show Gist options
  • Select an option

  • Save rtmalone/0357698feb741caba49706cc2ca6ac38 to your computer and use it in GitHub Desktop.

Select an option

Save rtmalone/0357698feb741caba49706cc2ca6ac38 to your computer and use it in GitHub Desktop.
LWC Event callback to report validity of fields in a form
/**
* Uses a JS Map structure to easily set & enforce unique keys.
* Map Iterator is turned into an Array then ultimately reduced to
* a single boolean for the Save button to disable against
*
* @param {Event} event
*/
formValidityCallback(event) {
const { fieldId, isValid } = event.detail;
this.validityMap.set(fieldId, isValid);
this.isSaveDisabled = !Array.from(this.validityMap)
.map((item) => item[1])
.reduce((validSoFar, validity) => {
return validSoFar && validity;
}, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment