Skip to content

Commit c20166d

Browse files
committed
Merge branch 'master' into production
2 parents 3b150c1 + ab585a0 commit c20166d

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

src/formGroup.vue

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
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">
4+
<span>
5+
<i v-if="hasIconBefore" :class="field.labelIcon.iconClass" />
6+
{{ field.label }}
7+
<i v-if="hasIconAfter" :class="field.labelIcon.iconClass" />
8+
</span>
59
<span v-if="field.help" class="help">
610
<i class="icon" />
711
<div class="helpText">{{ field.help }}</div>
@@ -42,12 +46,14 @@
4246
</div>
4347
</div>
4448
</template>
49+
4550
<script>
4651
import { get as objGet, isNil, isFunction } from 'lodash'
4752
import { slugifyFormID } from './utils/schema'
4853
import formMixin from './formMixin.js'
4954
import * as fieldComponents from './utils/fieldsLoader'
5055
import { ref } from 'vue'
56+
5157
export default {
5258
name: 'FormGroup',
5359
components: fieldComponents,
@@ -77,6 +83,37 @@ export default {
7783
child: ref()
7884
}
7985
},
86+
computed: {
87+
hasIconBefore () {
88+
return this.field.labelIcon && this.field.labelIcon.iconClass && this.field.labelIcon.position === 'before'
89+
},
90+
hasIconAfter () {
91+
return this.field.labelIcon && this.field.labelIcon.iconClass && this.field.labelIcon.position === 'after'
92+
},
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+
}
116+
},
80117
methods: {
81118
onBlur (newValue, schema) {
82119
this.$emit('blur', newValue, schema)
@@ -95,29 +132,6 @@ export default {
95132
}
96133
return res
97134
},
98-
fieldTypeHasLabel(field) {
99-
if (isNil(field.label)) return false
100-
101-
let relevantType = ''
102-
if (field.type === 'input') {
103-
relevantType = field.inputType
104-
} else {
105-
relevantType = field.type
106-
}
107-
108-
switch (relevantType) {
109-
case 'button':
110-
case 'submit':
111-
case 'reset':
112-
return false
113-
default:
114-
return true
115-
}
116-
},
117-
getFieldID(schema) {
118-
const idPrefix = objGet(this.options, 'fieldIdPrefix', '')
119-
return slugifyFormID(schema, idPrefix)
120-
},
121135
// Get type of field 'field-xxx'. It'll be the name of HTML element
122136
getFieldType(fieldSchema) {
123137
return 'field-' + fieldSchema.type

0 commit comments

Comments
 (0)