File tree Expand file tree Collapse file tree 6 files changed +16
-24
lines changed Expand file tree Collapse file tree 6 files changed +16
-24
lines changed Original file line number Diff line number Diff line change 1
1
<script setup>
2
- import { ref , computed } from ' vue'
3
- import { getFieldComponentName , hasLabel } from ' @/helpers'
2
+ import { computed , useTemplateRef } from ' vue'
3
+ import { getFieldComponentName } from ' @/helpers'
4
4
5
- const fieldComponent = ref ( null )
5
+ const fieldComponent = useTemplateRef ( ' fieldComponent ' )
6
6
7
7
const props = defineProps ({
8
8
formOptions: {
@@ -39,8 +39,10 @@ const fieldId = computed(() => {
39
39
})
40
40
41
41
const shouldHaveLabel = computed (() => {
42
- // checkbox will have their own label
43
- return hasLabel (props .field ) && ! [ props .field .inputType , props .field .type ].includes (' checkbox' ) && ! props .field .noLabel
42
+ if (fieldComponent .value ? .noLabel || props .field .noLabel === true ) {
43
+ return false
44
+ }
45
+ return props .field .label
44
46
})
45
47
< / script>
46
48
Original file line number Diff line number Diff line change @@ -11,4 +11,6 @@ import { useFieldProps } from '@/composables/index.ts'
11
11
const props = defineProps (useFieldProps ())
12
12
13
13
const { model , field } = toRefs (props)
14
+
15
+ defineExpose ({ noLabel: true })
14
16
</script >
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<input
3
- :id =" id"
3
+ :id =" props. id"
4
4
type =" checkbox"
5
5
:name =" field.name"
6
6
:required =" isRequired"
9
9
:checked =" currentModelValue"
10
10
@change =" onFieldValueChanged"
11
11
>
12
- <label v-if =" field.label" style =" margin-left : .4em " :for =" id" > {{ field.label }}</label >
12
+ <label v-if =" field.label" style =" margin-left : .4em " :for =" props. id" > {{ field.label }}</label >
13
13
</template >
14
14
15
15
<script setup>
@@ -49,5 +49,5 @@ const onFieldValueChanged = ({ target }) => {
49
49
emits (' onInput' , target .checked )
50
50
}
51
51
52
- defineExpose ({ hint })
52
+ defineExpose ({ hint, noLabel : true })
53
53
</script >
Original file line number Diff line number Diff line change @@ -9,4 +9,6 @@ import { useFieldProps } from '@/composables/index.ts'
9
9
const props = defineProps (useFieldProps ())
10
10
11
11
const { field } = toRefs (props)
12
+
13
+ defineExpose ({ noLabel: true })
12
14
</script >
Original file line number Diff line number Diff line change @@ -17,4 +17,6 @@ const props = defineProps(useFieldProps())
17
17
const { model , field } = toRefs (props)
18
18
19
19
const { isDisabled } = useFieldAttributes (model .value , field .value )
20
+
21
+ defineExpose ({ noLabel: true })
20
22
</script >
Original file line number Diff line number Diff line change @@ -66,22 +66,6 @@ export function isNotEmpty (value: any): boolean {
66
66
return ! isEmpty ( value )
67
67
}
68
68
69
- /**
70
- * Determine if a field should have a top-level label.
71
- */
72
- export function hasLabel ( field : Field ) : boolean {
73
- if ( ! ( 'label' in field ) || ! field . label ) return false
74
-
75
- switch ( field . type ) {
76
- case 'button' :
77
- case 'submit' :
78
- case 'reset' :
79
- return false
80
- default :
81
- return true
82
- }
83
- }
84
-
85
69
/**
86
70
* Reset all properties to an empty value of the same type. Will recursively try and
87
71
* reset all properties if an object has a property with another object as its value.
You can’t perform that action at this time.
0 commit comments