Skip to content

Commit

Permalink
vue: FixedValue now supports empty labels
Browse files Browse the repository at this point in the history
Change-Id: I7ea7a8a4f655aab9b09bc8813421e6143eefb2e7
  • Loading branch information
schnetzzz committed Sep 24, 2024
1 parent 0fc739e commit c241ab1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ function renderBooleanChoice(formSpec: BooleanChoice, value: boolean): VNode {
}

function renderFixedValue(formSpec: FixedValue): VNode {
const shownValue = formSpec.label ? formSpec.label : formSpec.value
let shownValue = formSpec.value
if (formSpec.label != null) {
shownValue = formSpec.label
}
return h('div', shownValue as string)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ const [validation, _value] = useValidation<unknown>(
)

const fixedValue = computed(() => {
return props.spec.label || props.spec.value
if (props.spec.label != null) {
return props.spec.label
}
return props.spec.value
})
</script>

<template>
<label>{{ fixedValue }}</label>
<FormValidation :validation="validation"></FormValidation>
<label v-if="fixedValue">{{ fixedValue }}</label>
<FormValidation v-if="fixedValue" :validation="validation"></FormValidation>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import type * as FormSpec from '@/form/components/vue_formspec_components'
import FormFixedValue from '@/form/components/forms/FormFixedValue.vue'

function getFixedValue(withLabel = false): FormSpec.FixedValue {
return {
const spec: FormSpec.FixedValue = {
type: 'fixed_value',
title: 'fooTitle',
help: 'fooHelp',
validators: [],
label: withLabel ? 'fooLabel' : '',
value: '42'
}
if (withLabel) {
spec['label'] = 'fooLabel'
}
return spec
}

test('FormFixedValue renders value', () => {
Expand Down

0 comments on commit c241ab1

Please sign in to comment.