Not sure how to delete a question, but I would delete this one if I could. I realized the issue wasn't the above code (though it does have it's problems). It has to do with not returning the value of the selected radio button. Anyhow, here's my follow up question which I hope makes more sense.
Jun 4, 2022
1
Level 3
updating prop values after Inertia.get() response in watch
I have a form that has a field of radio buttons. I want the radio buttons to act as a filter for prop. I have a watcher set to send a request when the value of the field changes. I can't figure out how to update the value of the prop with the response. The code is below. I'm very new and pretty sure I'm using watch incorrectly and probably going about it the wrong way. Any help would be appreciated.
<script setup>
const props = defineProps({
mealServices: Array,
activeMealService: Array,
});
let form = useForm({
date_served: '',
meal_type_id: '',
group: ''
});
let storeTally = () => {
form.post('/pos')
};
onBeforeMount(() => {
let currentTime = new Date();
let clientTime = currentTime.toTimeString();
let i = 0;
while (i < props.mealServices.length) {
if(clientTime < props.mealServices[i].end_time) {
form.meal_type_id = props.mealServices[i].meal_type_id;
i = props.mealServices.length;
} else {
i++
form.meal_type_id = 1;
};
};
});
watch(form, value => {
Inertia.get('/pos', {mealType: form.meal_type_id},{
preserveState: true,
replace: true,
deep: true,
});
console.log('meal id is ' + form.meal_type_id)
console.log('meal id is ' + props.activeMealService.meal_type_id)
});
Please or to participate in this conversation.