srcdev-nuxt-forms 2.1.19 → 2.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@
16
16
  :class="[size, { error: fieldHasError }, { 'is-button': isButton }]"
17
17
  v-model="modelValue"
18
18
  ref="inputField"
19
+ :aria-checked="isChecked"
19
20
  />
20
21
  </div>
21
22
  </template>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <fieldset class="multiple-radiobuttons-fieldset" :class="[{ error: fieldHasError }]">
2
+ <fieldset :aria-required="required" :aria-invalid="fieldHasError" role="radiogroup" class="multiple-radiobuttons-fieldset" :class="[{ error: fieldHasError }]">
3
3
  <legend :class="[{ 'has-description': hasDescription }]">{{ legend }}</legend>
4
4
  <template v-if="hasDescription">
5
5
  <slot name="description"></slot>
@@ -1,8 +1,8 @@
1
1
  import { ref, reactive, toRaw, type Ref } from 'vue';
2
2
  import { z, ZodError } from 'zod';
3
- import type { IFormFieldStateObj, ApiErrorResponse } from '../types/types.forms';
3
+ import type { ApiErrorResponse } from '../types/types.forms';
4
4
 
5
- const useZodValidation = (formSchema: any) => {
5
+ const useZodValidation = (formSchema: any, formRef: Ref<HTMLFormElement | null>) => {
6
6
  const zodFormControl = reactive({
7
7
  errorCount: 0,
8
8
  displayLoader: false,
@@ -83,6 +83,7 @@ const useZodValidation = (formSchema: any) => {
83
83
  zodFormControl.formIsValid = zodFormControl.errorCount === 0;
84
84
  zodFormControl.displayLoader = false;
85
85
  zodFormControl.submitAttempted = true;
86
+ scrollToFirstError();
86
87
  return zodErrorObj.value;
87
88
  };
88
89
 
@@ -108,6 +109,29 @@ const useZodValidation = (formSchema: any) => {
108
109
  return null;
109
110
  };
110
111
 
112
+ const scrollToFirstError = async () => {
113
+ await nextTick();
114
+ if (formRef.value) {
115
+ const firstErrorElement = formRef.value.querySelector('[aria-invalid=true]');
116
+ window.scrollTo({
117
+ top: firstErrorElement?.getBoundingClientRect().y,
118
+ left: 0,
119
+ behavior: 'smooth',
120
+ });
121
+ }
122
+ };
123
+
124
+ const scrollToFormHead = () => {
125
+ if (formRef.value) {
126
+ const formHead = formRef.value.getBoundingClientRect().top;
127
+ window.scrollTo({
128
+ top: formHead,
129
+ left: 0,
130
+ behavior: 'smooth',
131
+ });
132
+ }
133
+ };
134
+
111
135
  return {
112
136
  initZodForm,
113
137
  zodFormControl,
@@ -115,6 +139,8 @@ const useZodValidation = (formSchema: any) => {
115
139
  pushCustomErrors,
116
140
  doZodValidate,
117
141
  fieldMaxLength,
142
+ scrollToFirstError,
143
+ scrollToFormHead,
118
144
  };
119
145
  };
120
146
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-forms",
3
3
  "type": "module",
4
- "version": "2.1.19",
4
+ "version": "2.1.21",
5
5
  "main": "nuxt.config.ts",
6
6
  "scripts": {
7
7
  "clean": "rm -rf .nuxt && rm -rf .output && rm -rf .playground/.nuxt && rm -rf .playground/.output",