-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from ssciwr/fix_57_add_other_option_to_selects
Add free text other option for source/tumor type/platform
- Loading branch information
Showing
2 changed files
with
69 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script setup lang="ts"> | ||
import { ref, computed, watch } from "vue"; | ||
import { FwbSelect, FwbInput } from "flowbite-vue"; | ||
const model = defineModel(); | ||
const otherText = "Other (please specify)"; | ||
const textInput = ref(""); | ||
const selectInput = ref(""); | ||
const showTextInput = ref(true); | ||
type OptionsType = { | ||
name: string; | ||
value: string; | ||
}; | ||
watch([selectInput, textInput], ([newSelectInput, newTextInput]) => { | ||
if (newSelectInput === otherText) { | ||
showTextInput.value = true; | ||
model.value = newTextInput; | ||
} else { | ||
showTextInput.value = false; | ||
textInput.value = ""; | ||
model.value = newSelectInput; | ||
} | ||
}); | ||
function string_to_options(str: string): Array<OptionsType> { | ||
const items = `${str};${otherText}`.split(";"); | ||
return items.map((x) => ({ value: x, name: x })); | ||
} | ||
const props = defineProps({ | ||
options: String, | ||
id: String, | ||
label: String, | ||
}); | ||
const optionsArray = computed(() => { | ||
if (!props.options) { | ||
return []; | ||
} | ||
return string_to_options(props.options); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-row mb-2"> | ||
<fwb-select | ||
v-model="selectInput" | ||
:options="optionsArray" | ||
:id="id" | ||
:label="label" | ||
class="grow" | ||
/> | ||
<fwb-input | ||
v-if="showTextInput" | ||
v-model="textInput" | ||
label="Other" | ||
class="ml-2 grow" | ||
/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters