Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mpk123's avatar

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)


});

0 likes
1 reply

Please or to participate in this conversation.