The only way I can submit the radio button values is by clicking them individually on each slide even if they are pre-selected hitting my next button only goes to the next slide and won't update the radio button value.
e.g. I go to a slide, It has a radio button pre-selected and I happen to agree with that radio button selection. I hit the "next" button to go to the next slide however that pre-selected radio button value is not stored. *How do I get the 'next' button to actually store the value of the pre-selected slide? Instead of just moving to the next one? - note that the next button exists outside the slide on the page and calls the next slide in code, the code for it is:
export function nextButton_click(event, $w) { $w('#slideshow').next(); }
The problem is that the value is not being submitted when I hit "next" not when I'm changing the radio button value. The value isn't being read even if it is pre-populated.
Try adding $w(#yourdatasetname).save(); to the radio button on change event
@Yoav (Wix) So basically what my code does is create averages based on the radio button values that are selected within each section then it creates an overall score averaging all the values gathered by the radio button group arrays.
In the editor interface the buttons pre-selected so that when it loads the button values are not empty. The problem is: while the radio buttons are selected by default, their values are not being registered when the radio button group loads. The only time they are being captured is onchange as you mentioned. I would like the radio button values to be loaded into the averaging algorithm. so when the user agrees with a pre-selected radio button they can simply hit the 'next' button. I hope this makes sense. I'm unsure how to achieve this in code your help is greatly appreciated!
This is all my code.
export function nextButton_click(event, $w) { $w('#slideshow').next(); } export function prevButton_click(event, $w) { $w('#slideshow').previous(); } $w.onReady (function () { let avg1, avg2, avg3, avg4; let finalAvg; function calculateFinalAvg(){ let allAverages = [avg1, avg2, avg3, avg4]; if (allAverages.every(e => typeof e === "number")){ finalAvg = Math.round(allAverages.reduce((a, c) => a + c)/allAverages.length); $w("#text150").text = finalAvg.toString() } } calculateFinalAvg(); const section1 = [$w("#radioGroup1"), $w("#radioGroup2"), $w("#radioGroup3"), $w("#radioGroup4")]; let s1totalCount = 0; section1.forEach(e => { e.onChange((event) => { let selected = section1.filter(o => o.valid); s1totalCount = selected.reduce((a, c) => a + Number(c.value), 0); avg1 = Math.round(s1totalCount / section1.length); calculateFinalAvg(); $w("#text57").text = avg1.toString(); }) }) const section2 = [$w("#radioGroup5"), $w("#radioGroup6"), $w("#radioGroup7"), $w("#radioGroup8")]; let s2totalCount = 0; section2.forEach(e => { e.onChange((event) => { let selected = section2.filter(o => o.valid); s2totalCount = selected.reduce((a, c) => a + Number(c.value), 0); avg2 = Math.round(s2totalCount / section2.length); calculateFinalAvg(); $w("#text153").text = avg2.toString(); }) }) const section3 = [$w("#radioGroup9"), $w("#radioGroup10"), $w("#radioGroup11"), $w("#radioGroup12")]; let s3totalCount = 0; section3.forEach(e => { e.onChange((event) => { let selected = section3.filter(o => o.valid); s3totalCount = selected.reduce((a, c) => a + Number(c.value), 0); avg3 = Math.round(s3totalCount / section3.length); calculateFinalAvg(); $w("#text121").text = avg3.toString(); }) }) const section4 = [$w("#radioGroup13"), $w("#radioGroup14"), $w("#radioGroup15"), $w("#radioGroup16")]; var s4totalCount = 0; section4.forEach(e => { e.onChange((event) => { var selected = section4.filter(o => o.valid); s4totalCount = selected.reduce((a, c) => a + Number(c.value), 0); avg4 = Math.round(s4totalCount / section4.length); calculateFinalAvg(); $w("#text156").text = avg4.toString(); }) }) })
I'm just storing the values in radio button groups e.g. $w("#radioGroup1") each have their own labels and values, When they select a radio button it is stored in the section1 array. - the rest of the code turns the output into an averaged score.
const section1 = [$w("#radioGroup1"), $w("#radioGroup2"), $w("#radioGroup3"), $w("#radioGroup4")]; let s1totalCount = 0; section1.forEach(e => { e.onChange((event) => { let selected = section1.filter(o => o.valid); s1totalCount = selected.reduce((a, c) => a + Number(c.value), 0); avg1 = Math.round(s1totalCount / section1.length); calculateFinalAvg(); $w("#text57").text = avg1.toString(); }) })