Skip to content

Commit 340624d

Browse files
authored
Merge pull request #3 from kevinkosterr/master
Release
2 parents c20166d + 6fad1d6 commit 340624d

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/directives/vAttributes.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function setAttributes (el, binding) {
2+
let attributes = {}
3+
4+
if (binding.instance.schema?.attributes) {
5+
attributes = { ...binding.instance.schema?.attributes }
6+
}
7+
8+
const container = binding.value || 'input'
9+
if ( typeof container === 'string' ) {
10+
attributes = attributes[container] || attributes
11+
}
12+
13+
Object.entries(attributes).forEach(([ key, value ]) => {
14+
el.setAttribute(key, value)
15+
})
16+
}
17+
18+
export const vAttributes = {
19+
beforeMount: (el, binding) => setAttributes(el, binding),
20+
updated: (el, binding) => setAttributes(el, binding)
21+
}

src/fields/abstractField.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// @ts-nocheck
22
import { get as objGet, forEach, isFunction, isString, isArray, debounce, uniqueId, uniq as arrayUniq } from 'lodash'
3-
import validators from '../utils/validators'
4-
import { slugifyFormID } from '../utils/schema'
3+
import { slugifyFormID } from '@/utils/schema'
4+
import { vAttributes } from '@/directives/vAttributes'
5+
6+
import validators from '@/utils/validators'
7+
58
function convertValidator(validator) {
69
if (isString(validator)) {
710
if (validators[validator] != null) return validators[validator]
@@ -13,16 +16,6 @@ function convertValidator(validator) {
1316
return validator
1417
}
1518

16-
function attributesDirective(el, binding, vnode) {
17-
let attrs = objGet(vnode.context, 'schema.attributes', {})
18-
let container = binding.value || 'input'
19-
if (isString(container)) {
20-
attrs = objGet(attrs, container) || attrs
21-
}
22-
forEach(attrs, (val, key) => {
23-
el.setAttribute(key, val)
24-
})
25-
}
2619
export default {
2720
name: 'abstractField',
2821
props: [ 'vfg', 'model', 'schema', 'formOptions', 'disabled' ],
@@ -34,11 +27,7 @@ export default {
3427
}
3528
},
3629
directives: {
37-
attributes: {
38-
beforeMount: attributesDirective,
39-
updated: attributesDirective,
40-
componentUpdated: attributesDirective
41-
}
30+
attributes: vAttributes
4231
},
4332
computed: {
4433
value: {

0 commit comments

Comments
 (0)