Allow form validation without focus
This commit is contained in:
parent
64eb21dfb8
commit
ae202b072b
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@fwdekker/template",
|
||||
"version": "3.2.0",
|
||||
"version": "3.2.1",
|
||||
"description": "The base template for pages on fwdekker.com.",
|
||||
"author": "Florine W. Dekker",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -123,13 +123,14 @@ export function clearInputValidity(input: HTMLInputElement): void {
|
|||
*
|
||||
* @param input the input to show as invalid
|
||||
* @param message the message explaining what is invalid
|
||||
* @param focus `true` if `input` should receive focus
|
||||
*/
|
||||
export function showInputInvalid(input: HTMLInputElement, message?: string): void {
|
||||
export function showInputInvalid(input: HTMLInputElement, message?: string, focus: boolean = true): void {
|
||||
clearInputValidity(input);
|
||||
|
||||
input.classList.add("invalid");
|
||||
input.setAttribute("aria-invalid", "true");
|
||||
input.focus();
|
||||
if (focus) input.focus();
|
||||
|
||||
const label = $(`label[for="${input.id}"]`) ?? $(`*[data-label-for="${input.id}"]`);
|
||||
if (label != null)
|
||||
|
|
Loading…
Reference in New Issue