@drax/crud-vue 2.0.6 → 2.1.0

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.0.6",
6
+ "version": "2.1.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "module": "./src/index.ts",
@@ -50,5 +50,5 @@
50
50
  "vue-tsc": "^3.2.4",
51
51
  "vuetify": "^3.11.8"
52
52
  },
53
- "gitHead": "9ccda70d228007d50fe535b26d719148318086fa"
53
+ "gitHead": "44c490f35d122a1d2f8533f5de0e17dbb4fbaacb"
54
54
  }
package/src/EntityCrud.ts CHANGED
@@ -141,7 +141,7 @@ class EntityCrud implements IEntityCrud {
141
141
  throw new Error("Ref not found: " + ref)
142
142
  }
143
143
 
144
- return this.refs[ref]
144
+ return this.refs[ref] as IEntityCrud
145
145
  }
146
146
 
147
147
  get rules(): IEntityCrudRules {
@@ -8,6 +8,7 @@ import type {PropType} from "vue";
8
8
  import {useCrudStore} from "../stores/UseCrudStore";
9
9
  import {useCrud} from "../composables/UseCrud";
10
10
  import {useAuth} from '@drax/identity-vue'
11
+ import type {ValidationRule} from "vuetify";
11
12
 
12
13
  const {hasPermission} = useAuth()
13
14
  const {t, te} = useI18n()
@@ -125,6 +126,11 @@ const menuInputErrors = computed(() => {
125
126
  }
126
127
  )
127
128
 
129
+ const rules = computed(() => {
130
+ return (fieldName: string) => {
131
+ return entity.getRule(fieldName) as ValidationRule[] || undefined
132
+ }
133
+ })
128
134
 
129
135
  </script>
130
136
 
@@ -165,6 +171,7 @@ const menuInputErrors = computed(() => {
165
171
  :append-inner-icon="field?.appendInnerIcon"
166
172
  :preview="field?.preview"
167
173
  :previewHeight="field?.previewHeight"
174
+ :rules="rules(field.name)"
168
175
  />
169
176
  </slot>
170
177
 
@@ -206,6 +213,7 @@ const menuInputErrors = computed(() => {
206
213
  :prepend-icon="field?.prependIcon"
207
214
  :append-icon="field?.appendIcon"
208
215
  :append-inner-icon="field?.appendInnerIcon"
216
+ :rules="rules(field.name)"
209
217
  />
210
218
  </slot>
211
219
 
@@ -259,6 +267,7 @@ const menuInputErrors = computed(() => {
259
267
  :prepend-icon="field?.prependIcon"
260
268
  :append-icon="field?.appendIcon"
261
269
  :append-inner-icon="field?.appendInnerIcon"
270
+ :rules="rules(field.name)"
262
271
  />
263
272
  </slot>
264
273
 
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import {computed, ref} from "vue";
3
+ import type {ValidationRule} from "vuetify"
3
4
  import type {PropType} from "vue";
4
5
  import CrudFormList from "./CrudFormList.vue";
5
6
  import CrudAutocomplete from "./CrudAutocomplete.vue";
@@ -15,11 +16,9 @@ const {t, te} = useI18n()
15
16
 
16
17
  const {hasPermission} = useAuth()
17
18
 
18
-
19
-
20
19
  const valueModel = defineModel<any>({type: [String, Number, Boolean, Object, Array], default: false})
21
20
 
22
- const {index, entity, field, disableRules, parentField} = defineProps({
21
+ const {index, entity, field, disableRules, parentField, errorMessages, rules} = defineProps({
23
22
  entity: {type: Object as PropType<IEntityCrud>, required: true},
24
23
  field: {type: Object as PropType<IEntityCrudField | IEntityCrudFilter | undefined>, required: true},
25
24
  prependIcon: {type: String, default: ''},
@@ -35,6 +34,8 @@ const {index, entity, field, disableRules, parentField} = defineProps({
35
34
  preview: {type: Boolean, default: true},
36
35
  previewHeight: {type: String, default: '100px'},
37
36
  parentField: {type: String, default: null, required: false},
37
+ errorMessages: {type: Array as PropType<string[]>, default: null, required: false},
38
+ rules: {type: Array as PropType<ValidationRule[]>, required: false},
38
39
  index: {type: Number, default: null, required: false},
39
40
  density: {type: String as PropType<'comfortable' | 'compact' | 'default'>, default: 'default'},
40
41
  variant: {
@@ -59,20 +60,22 @@ const label = computed(() => {
59
60
  return te(i18n) ? t(i18n) : field.label
60
61
  })
61
62
 
62
- const rules = computed(() => {
63
- if (disableRules) return undefined
64
- return entity.getRule(field.name) as any
65
- })
66
63
 
67
- const inputErrors = computed(() => {
64
+
65
+ const storeErrorMessages = computed(() => {
68
66
  let sIndex = (index != null && index >= 0) ? `${index}.` : ''
69
67
  let name = parentField ? `${parentField}.${sIndex}${field.name}` : field.name
70
68
  return store.getFieldInputErrors(name).map((error: string) =>te(error) ? t(error) : error)
71
69
  }
72
70
  )
73
71
 
72
+ const inputErrors = computed(() => {
73
+ return errorMessages ?? storeErrorMessages.value
74
+ })
75
+
74
76
  defineEmits(['updateValue'])
75
77
 
78
+
76
79
  </script>
77
80
 
78
81
  <template>
@@ -399,7 +399,8 @@ export function useCrud(entity: IEntityCrud) {
399
399
 
400
400
 
401
401
  return {
402
- doPaginate, doExport, onView, onCreate, onEdit, onDelete, onCancel, onSubmit, resetCrudStore,
402
+ doPaginate, doExport, doUpdate, doCreate, doDelete,
403
+ onView, onCreate, onEdit, onDelete, onCancel, onSubmit, resetCrudStore,
403
404
  operation, dialog, form, notify, error, message, formValid,
404
405
  loading, itemsPerPage, page, sortBy, search, totalItems, items,
405
406
  prepareFilters, filters, clearFilters, applyFilters,