I have running into a few issues and most of them were solved by @ldebeasi, who took his time to help me. However, I got into another issue because I need to pass values to the function that submits the form but it’s not working. I mean I either pass the form or I pre define a value for the radio input…I can’t do both, it just won’t work.
This pre selects the value:
<ion-label>Accept</ion-label>
<ion-radio-group value="yes">
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio slot="start" value="yes"></ion-radio>
</ion-item>
<ion-item>
<ion-label >No</ion-label>
<ion-radio slot="start" value="no"></ion-radio>
</ion-item>
</ion-radio-group>
This pass the value to the function:
<ion-label>Accept</ion-label>
<ion-radio-group v-model="accept">
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio slot="start" value="yes"></ion-radio>
</ion-item>
<ion-item>
<ion-label >No</ion-label>
<ion-radio slot="start" value="no"></ion-radio>
</ion-item>
</ion-radio-group>
But if I want to do both:
<ion-label>Accept</ion-label>
<ion-radio-group v-model="accept" value="yes>
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio slot="start" value="yes"></ion-radio>
</ion-item>
<ion-item>
<ion-label >No</ion-label>
<ion-radio slot="start" value="no"></ion-radio>
</ion-item>
</ion-radio-group>
it simply doesn’t work.
That’s my whole code:
<ion-label>Accept</ion-label>
<ion-radio-group v-model="accept" value="yes">
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio slot="start" value="yes"></ion-radio>
</ion-item>
<ion-item>
<ion-label >No</ion-label>
<ion-radio slot="start" value="no"></ion-radio>
</ion-item>
</ion-radio-group>
<ion-button @click="submit(accept)">Save New Member</ion-button>
<script lang="ts">
import { IonButtons,actionSheetController, alertController, IonInput, IonItem, IonLabel, IonList, IonListHeader, IonRadioGroup, IonRadio, IonTextarea, IonContent, IonHeader, IonMenuButton, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
import {useRoute} from "vue-router";
import {ref, onMounted, defineComponent } from 'vue';
export default defineComponent({
name: 'Folder',
components: {
IonButtons,
IonContent,
IonHeader,
IonItem,
IonInput,
IonRadioGroup,
IonRadio,
IonMenuButton,
IonPage,
IonTextarea,
IonTitle,
IonToolbar
},
//Data from the inputs
data(){
return{
accept:"",
};
},
setup(){
const route=useRoute();
return{
route
};
},
methods: {
//get data from the inputs/form
submit:function(accept: any){
console.log(accept);
},
},
})
</script>
Is there any way to pre select a radio input and pass its value like we normally do with v-model
? Like a checked attribute or something?
The docs I’m trying to follow along: