Created
December 10, 2021 20:33
-
-
Save rtmalone/0357698feb741caba49706cc2ca6ac38 to your computer and use it in GitHub Desktop.
LWC Event callback to report validity of fields in a form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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