Skip to content

Commit ab585a0

Browse files
committed
refactor: some methods to computed values
1 parent 2215044 commit ab585a0

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/formGroup.vue

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<div class="form-group" :class="getFieldRowClasses(field)">
3-
<label v-if="fieldTypeHasLabel(field)" :for="getFieldID(field)" :class="field.labelClasses">
4-
<span>{{ field.label }}</span>
3+
<label v-if="hasLabel" :for="fieldId" :class="field.labelClasses">
54
<span>
65
<i v-if="hasIconBefore" :class="field.labelIcon.iconClass" />
76
{{ field.label }}
@@ -91,6 +90,29 @@ export default {
9190
hasIconAfter () {
9291
return this.field.labelIcon && this.field.labelIcon.iconClass && this.field.labelIcon.position === 'after'
9392
},
93+
hasLabel() {
94+
if (isNil(this.field.label)) return false
95+
96+
let relevantType = ''
97+
if (this.field.type === 'input') {
98+
relevantType = this.field.inputType
99+
} else {
100+
relevantType = this.field.type
101+
}
102+
103+
switch (relevantType) {
104+
case 'button':
105+
case 'submit':
106+
case 'reset':
107+
return false
108+
default:
109+
return true
110+
}
111+
},
112+
fieldId () {
113+
const idPrefix = this.options?.fieldIdPrefix ?? ''
114+
return slugifyFormID(this.field, idPrefix)
115+
}
94116
},
95117
methods: {
96118
onBlur (newValue, schema) {
@@ -110,29 +132,6 @@ export default {
110132
}
111133
return res
112134
},
113-
fieldTypeHasLabel(field) {
114-
if (isNil(field.label)) return false
115-
116-
let relevantType = ''
117-
if (field.type === 'input') {
118-
relevantType = field.inputType
119-
} else {
120-
relevantType = field.type
121-
}
122-
123-
switch (relevantType) {
124-
case 'button':
125-
case 'submit':
126-
case 'reset':
127-
return false
128-
default:
129-
return true
130-
}
131-
},
132-
getFieldID(schema) {
133-
const idPrefix = objGet(this.options, 'fieldIdPrefix', '')
134-
return slugifyFormID(schema, idPrefix)
135-
},
136135
// Get type of field 'field-xxx'. It'll be the name of HTML element
137136
getFieldType(fieldSchema) {
138137
return 'field-' + fieldSchema.type

0 commit comments

Comments
 (0)