srcdev-nuxt-forms 6.0.0 → 6.0.1

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.
@@ -1,4 +1,4 @@
1
- import type { InpuTextC12, IFormFieldC12, IFormData } from '@/types/types.forms';
1
+ import type { InpuTextC12, IFormFieldC12, IFormData } from '../../../../shared/types/types.forms';
2
2
 
3
3
  const formFieldC12 = <IFormFieldC12>{
4
4
  label: '',
@@ -62,7 +62,7 @@
62
62
 
63
63
  <script setup lang="ts">
64
64
  import propValidators from '../c12/prop-validators';
65
- import type { IOptionsConfig, IFormMultipleOptions } from '@/types/types.forms';
65
+ import type { IOptionsConfig, IFormMultipleOptions } from '../../../../shared/types/types.forms';
66
66
 
67
67
  const { dataTestid, name, legend, label, required, fieldHasError, placeholder, isButton, errorMessage, size, optionsLayout, equalCols, styleClassPassthrough, theme, direction } = defineProps({
68
68
  dataTestid: {
@@ -22,7 +22,7 @@
22
22
 
23
23
  <script setup lang="ts">
24
24
  import propValidators from '../c12/prop-validators';
25
- import type { IFormMultipleOptions } from '@/types/types.forms';
25
+ import type { IFormMultipleOptions } from '../../../../shared/types/types.forms';
26
26
 
27
27
  const props = defineProps({
28
28
  dataTestid: {
@@ -60,7 +60,7 @@
60
60
 
61
61
  <script setup lang="ts">
62
62
  import propValidators from '../c12/prop-validators';
63
- import type { IFormMultipleOptions } from '@/types/types.forms';
63
+ import type { IFormMultipleOptions } from '../../../../shared/types/types.forms';
64
64
 
65
65
  const props = defineProps({
66
66
  dataTestid: {
@@ -12,7 +12,7 @@
12
12
 
13
13
  <script setup lang="ts">
14
14
  import propValidators from '../c12/prop-validators';
15
- import type { IFormMultipleOptions } from '@/types/types.forms';
15
+ import type { IFormMultipleOptions } from '../../../../shared/types/types.forms';
16
16
 
17
17
  const props = defineProps({
18
18
  id: {
@@ -36,7 +36,7 @@
36
36
 
37
37
  <script setup lang="ts">
38
38
  import propValidators from '../../c12/prop-validators';
39
- import type { IFormMultipleOptions } from '@/types/types.forms';
39
+ import type { IFormMultipleOptions } from '../../../../../shared/types/types.forms';
40
40
 
41
41
  const props = defineProps({
42
42
  dataTestid: {
@@ -1,4 +1,4 @@
1
- import type { IFormData } from '@/types/types.forms';
1
+ import type { IFormData } from '../../shared/types/types.forms';
2
2
 
3
3
  export function useErrorMessage(name: string, formData: Ref<IFormData>) {
4
4
  const defaultError = ref('');
@@ -12,7 +12,7 @@ export function useErrorMessage(name: string, formData: Ref<IFormData>) {
12
12
  console.log(`errorMessage()`);
13
13
  if (hasCustomError()) {
14
14
  console.log(`errorMessage() | IF`);
15
- return errorMessages.value[name].message;
15
+ return errorMessages.value[name]?.message;
16
16
  } else {
17
17
  return defaultError.value;
18
18
  }
@@ -1,5 +1,5 @@
1
- import type { IFormData, IFieldsInitialState, IFormFieldC12, IApiErrorMessages, ICustomErrorMessage, IErrorMessagesArr } from '@/types/types.forms';
2
- import { formFieldC12 } from '@/components/forms/c12/utils';
1
+ import type { IFormData, IFieldsInitialState, IFormFieldC12, IApiErrorMessages, ICustomErrorMessage, IErrorMessagesArr } from '../../shared/types/types.forms';
2
+ // import { formFieldC12 } from '@/components/forms/c12/utils';
3
3
 
4
4
  // export function useFormControl(name: string = '') {
5
5
  export function useFormControl(name: string = '') {
@@ -50,7 +50,13 @@ export function useFormControl(name: string = '') {
50
50
  console.log(`useFormControl | updatePreviousValues`);
51
51
 
52
52
  Object.keys(formData.value.data).forEach((key) => {
53
- formData.value.formFieldsC12[key].previousValue = formData.value.data[key];
53
+ if (formData.value.formFieldsC12[key]) {
54
+ const currentValue = formData.value.data[key];
55
+ // Filter out undefined values and IOptionsValueArr[] which are not supported by previousValue
56
+ if (currentValue !== undefined && !Array.isArray(currentValue)) {
57
+ formData.value.formFieldsC12[key].previousValue = currentValue;
58
+ }
59
+ }
54
60
  });
55
61
  };
56
62
 
@@ -86,7 +92,7 @@ export function useFormControl(name: string = '') {
86
92
  let count = 0;
87
93
 
88
94
  for (const key in obj) {
89
- if (obj.hasOwnProperty(key) && obj[key].useCustomError === true) {
95
+ if (obj.hasOwnProperty(key) && obj[key]?.useCustomError === true) {
90
96
  count++;
91
97
  }
92
98
  }
@@ -108,11 +114,11 @@ export function useFormControl(name: string = '') {
108
114
  */
109
115
  const updateErrorMessages = async (name: string, message: string = '', valid: boolean = false) => {
110
116
  if (!valid) {
111
- // formData.value.validityState[name] = valid;
112
- // formData.value.errorMessages[name] = {
113
- // useCustomError: true,
114
- // message,
115
- // };
117
+ // Ensure the form field exists before updating it
118
+ if (!formData.value.formFieldsC12[name]) {
119
+ console.warn(`Form field "${name}" not found in formFieldsC12`);
120
+ return;
121
+ }
116
122
 
117
123
  formData.value.formFieldsC12[name].useCustomError = true;
118
124
 
@@ -1,6 +1,6 @@
1
1
  import { ref, reactive, toRaw, type Ref } from 'vue';
2
2
  import { z, ZodError } from 'zod';
3
- import type { ApiErrorResponse } from '../types/types.forms';
3
+ import type { ApiErrorResponse } from '../../shared/types/types.forms';
4
4
 
5
5
  const useZodValidation = (formSchema: any, formRef: Ref<HTMLFormElement | null>) => {
6
6
  const zodFormControl = reactive({
package/nuxt.config.ts CHANGED
@@ -4,6 +4,9 @@ export default defineNuxtConfig({
4
4
  devtools: { enabled: true },
5
5
  css: ['modern-normalize', './app/assets/styles/main.css'],
6
6
  modules: ['@nuxt/icon', '@nuxt/test-utils/module'],
7
+ alias: {
8
+ '#shared': './shared',
9
+ },
7
10
  typescript: {
8
11
  tsConfig: {
9
12
  compilerOptions: {
@@ -31,7 +34,7 @@ export default defineNuxtConfig({
31
34
  runtimeCompiler: true,
32
35
  },
33
36
  compatibilityDate: '2024-12-01',
34
- // future: {
35
- // compatibilityVersion: 4,
36
- // },
37
+ future: {
38
+ compatibilityVersion: 4,
39
+ },
37
40
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcdev-nuxt-forms",
3
3
  "type": "module",
4
- "version": "6.0.0",
4
+ "version": "6.0.1",
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",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "files": [
21
21
  "app/",
22
+ "shared/",
22
23
  "nuxt.config.ts"
23
24
  ],
24
25
  "devDependencies": {
@@ -1,4 +1,4 @@
1
- import type { IFieldsInitialState, IFormFieldsState, IFormFieldsC12, IFormFieldC12, IApiErrorMessages, ICustomErrorMessage, IErrorMessagesArr } from '@/types/types.forms';
1
+ import type { IFieldsInitialState, IFormFieldsState, IFormFieldsC12, IFormFieldC12, IApiErrorMessages, ICustomErrorMessage, IErrorMessagesArr } from './types.forms';
2
2
 
3
3
  export interface IZodeFormControl {
4
4
  [x: string]: string | boolean | number | URL | object;