Skip to content

Commit ad081ef

Browse files
authored
Merge pull request #29 from redlink-gmbh/MORE-Platform#419-bugfix-for-required-boolean
MORE-Platform#419: boolean bugfix (set default in fe if backend has none)
2 parents 4959a5a + d5e37f1 commit ad081ef

4 files changed

Lines changed: 45 additions & 31 deletions

File tree

src/components/dialog/shared/BooleanPropertyInput.vue

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,58 @@ Oesterreichische Vereinigung zur Foerderung der wissenschaftlichen Forschung).
55
Licensed under the Elastic License 2.0. */
66
<script setup lang="ts">
77
import { BooleanProperty } from '../../../models/InputModels';
8-
import { PropType, watch } from 'vue';
8+
import { PropType, ref, watch } from 'vue';
99
import Checkbox from 'primevue/checkbox';
1010
import PartOfTemplateBadge from './PartOfTemplateBadge.vue';
1111
12-
const props = defineProps({
13-
property: {
14-
type: Object as PropType<BooleanProperty>,
15-
required: true,
16-
},
17-
isPartOfTemplate: {
18-
type: Boolean,
19-
default: false,
20-
},
21-
editable: {
22-
type: Boolean,
23-
default: true,
24-
},
25-
});
12+
const props =
13+
defineProps({
14+
property: {
15+
type: Object as PropType<BooleanProperty>,
16+
required: true,
17+
},
18+
isPartOfTemplate: {
19+
type: Boolean,
20+
default: false,
21+
},
22+
editable: {
23+
type: Boolean,
24+
default: true,
25+
},
26+
});
27+
28+
const tempValue = ref(props.property.value ?? false);
2629
2730
const emit = defineEmits<{
28-
(e: 'onBooleanChange', boolean: boolean | undefined): void;
31+
(e: 'onBooleanChange', boolean: boolean): void;
2932
}>();
3033
3134
watch(
32-
() => props.property.value,
35+
() => tempValue.value,
3336
() => {
34-
emit('onBooleanChange', props.property.value);
37+
emit('onBooleanChange', !!tempValue.value);
3538
},
3639
);
3740
</script>
3841

3942
<template>
4043
<div class="flex flex-col gap-1">
41-
<h6 class="font-bold flex items-center gap-1">
44+
<h6 class="flex items-center gap-1 font-bold">
4245
<label v-if="property.name" :for="property.id">
4346
{{ $t(property.name) }}<span v-if="property.required">*</span>
4447
</label>
45-
<PartOfTemplateBadge :visible="isPartOfTemplate" :component-id="property.id" />
48+
<PartOfTemplateBadge
49+
:visible="isPartOfTemplate"
50+
:component-id="property.id"
51+
/>
4652
</h6>
4753
<div v-if="props.property.description" :id="`${property.id}-help`">
4854
{{ $t(props.property.description) }}
4955
</div>
5056

5157
<div class="flex items-center">
5258
<Checkbox
53-
v-model="props.property.value"
59+
v-model="tempValue"
5460
:label="property.name"
5561
class="mr-2"
5662
:required="property.required"

src/i18n/de.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,8 @@
732732
"description": "Hier können Antwortmöglichkeiten für die Frage festgelegt werden. Nicht ausgefüllte Felder werden nicht mitgesendet."
733733
},
734734
"singleChoiceState": {
735-
"description": {
736-
"name": "Einfachauswahl aktivieren",
737-
"description": "Die obige Frage ist standardmäßig auf Mehrfachauswahl gesetzt. Durch Aktivieren dieser Funktion wird sie zu einer Einfachauswahl."
738-
}
735+
"name": "Einfachauswahl aktivieren",
736+
"description": "Die obige Frage ist standardmäßig auf Mehrfachauswahl gesetzt. Durch Aktivieren dieser Funktion wird sie zu einer Einfachauswahl."
739737
}
740738
}
741739
}

src/i18n/en.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -732,10 +732,8 @@
732732
"description": "Here you can define answer options for the question. Empty fields will not be sent."
733733
},
734734
"singleChoiceState": {
735-
"description": {
736-
"name": "Enable Single Choice",
737-
"description": "The question above is set to multiple choice by default. Enabling this function changes it to single choice."
738-
}
735+
"name": "Enable Single Choice",
736+
"description": "The question above is set to multiple choice by default. Enabling this function changes it to single choice."
739737
}
740738
}
741739
}

src/models/InputModels.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,26 @@ export class BooleanProperty extends Property<boolean> {
503503
}
504504

505505
validate(): string | undefined {
506-
if (this.required && this.value === undefined) {
506+
if (this.required && (this.value === undefined || this.value === null)) {
507507
return 'Value is required';
508-
} else if (typeof this.value !== 'boolean') {
508+
} else if (
509+
this.value !== undefined &&
510+
this.value !== null &&
511+
typeof this.value !== 'boolean'
512+
) {
509513
return 'Value has wrong value';
510514
} else {
511515
return undefined;
512516
}
513517
}
518+
519+
public getValue(): boolean | undefined {
520+
const error = this.validate();
521+
if (error) {
522+
throw new ValidationError(this.name, error);
523+
}
524+
return this.value ?? false;
525+
}
514526
static fromJson(json: any): BooleanProperty {
515527
return new BooleanProperty(
516528
json.defaultValue,

0 commit comments

Comments
 (0)