I am currently working on a form with a dropdown menu containing two options: "True" and "False". My goal is to save the selected value as a boolean in the form.
For instance, when the user selects "True", I want the value stored as true
in boolean format.
<select v-model="selected">
<option :value="null">Pick a value</option>
<option v-for="val in options">{{val}}</option>
</select>
...
data() {
return {
selected: null,
options: ["true", "false"]
}
If you'd like to see what I'm working on, here's a fiddle link: https://jsfiddle.net/q0nk9h32/5/
Do you have any suggestions on how I can display the selected values in their boolean form?
As a bonus question: Instead of using the options
variable, would it be considered valid syntax or good practice to use:
v-for="val in ["true", "false"]"
?
I feel like having a separate variable for this might be unnecessary (but when I tried using an array directly, it failed in the fiddle). Appreciate any insights!