Where are your radio buttons ? Can you share a complete explanation, so that we can better help you ? ;)
Alpine x-model on radio buttons issue
I'm trying to capture the total on a registration form for events. These have ad hoc questions created by app users, options that can accumulate costs for each. Some are quantity fields, others checkboxes, and I have those working to update my data total on the main form, but I'm having trouble with the radio buttons.
The radio options on one question might have 3 options, with different prices for each. I've used x-model and the following watch to capture when the selection changes.
<div class="form-group {{$wrapperClass}}"
x-data="{model{{$field->id}}: null}"
x-init="$watch('model{{$field->id}}', value => calculateTotal(value))"
>
And that works. But if in the function, how do I know if they have chosen a different radio option after updating my global total amount? Here's the calculateTotal function.
function calculateTotal(value){
//look at value, if set and remove that amount from total
//then add new selection to total
console.log(value)
}
How can I see the selected radio button, store that, and then subtract it from the global total if the user decides to choose a different option, especially knowing there may be multiple questions on the form with the different radio options and cost values on each.
Please or to participate in this conversation.