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 >
4246 </div >
4347 </div >
4448</template >
49+
4550<script >
4651import { get as objGet , isNil , isFunction } from ' lodash'
4752import { slugifyFormID } from ' ./utils/schema'
4853import formMixin from ' ./formMixin.js'
4954import * as fieldComponents from ' ./utils/fieldsLoader'
5055import { ref } from ' vue'
56+
5157export 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