diff --git a/src/index.ts b/src/index.ts index 47edca5..13e1fa0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -602,6 +602,24 @@ export class ValidationService { } } + + /** + * Focuses the first invalid element within the provided form + * @param form + */ + focusFirstInvalid = (form: HTMLFormElement) => { + let formUID = this.getElementUID(form); + let formInputUIDs = this.formInputs[formUID]; + let invalidFormInputUIDs = formInputUIDs.filter(uid => this.summary[uid]); + + if (invalidFormInputUIDs.length > 0) { + var firstInvalid = this.elementByUID[invalidFormInputUIDs[0]] as HTMLElement; + if (firstInvalid) { + firstInvalid.focus(); + } + } + } + /** * Tracks a