I am trying to assign a field value from a database to a radioGroup inside a repeater, and have the selected radioGroup value submitting to a writable form database.
Right now I am executing the submit in code using wixdata.insert, I have also tried with .save(). In every event a new entry is created, but the entries come up blank....even though a radio button was selected.
Right now I am setting the options of radioGroup1 to be the text #planInternet.
I have #planInternet connected to the database that is feeding the repeater....and so it is that value that I want to submit.
If I connect the submit button not using code....I get an entry equivalent to whatever is in the text box inside the editor. In this instance..."Plan Internet" is submitted.
Done using code...nothing gets submitted, but a new entry is successfully made.
I am not sure if I am using setFieldValue correctly...but I believe it hold the key to getting the database value over and into the submission dataset.
$item('#datasetSubmit').setFieldValue('tvInternet',$w('#radioGroup1').value);
Pic and current code below...
![](https://static.wixstatic.com/media/a27d24_dd048c89925b47b6a91ca7d3c7ebf853~mv2.jpg/v1/fill/w_902,h_710,al_c,q_85,enc_auto/a27d24_dd048c89925b47b6a91ca7d3c7ebf853~mv2.jpg)
import wixData from 'wix-data';
//TV Internet Repeater Radio Group// $w.onReady(function () { $w("#repeater1").onItemReady( (itemData, index) => { $w("#radioGroup1").options = [ {"label": "", "value": $w("#planInternet").text}, ]; $w("#radioGroup1").onClick( (event, $w) => { resetRadioButtons(); let $item = $w.at(event.context) $item("#radioGroup1").selectedIndex = 0; $item('#datasetSubmit').setFieldValue('tvInternet',$w('#radioGroup1').value); } ); }) }) export function resetRadioButtons () { $w('#radioGroup1').selectedIndex = undefined; }
$w.onReady(function () { let tvinternet let electric; let insurance; let movers; let security; }); export function submit_click(event, $w) {
let toInsert = {
'tvInternet' : $w('#radioGroup1').value,
'electric' : $w('#radioGroup2').value,
'insurance' : $w('#radioGroup3').value,
'movers' : $w('#radioGroup4').value,
'security' : $w('#radioGroup5').value,
}; wixData.insert("UtilitiesSubmission", toInsert) resetForm(); } function resetForm() { $w('#radioGroup1').value = '' }
How can I assign the field title of a radio button with wix code?
On your repeater you need to have the actual radio group set as the label and the value for the dataset field is given from that user choice and that needs to be set to the dataset field.
You will obviously get it without using code as you are not using the radio group value and are simply connecting the text element's value to the dataset field instead.
As it states in the API Reference.
Radio button groups are used for selecting one of a number of options. Radio button groups consist of a list of options. Each option contains a label, which is what the user sees, and a value, which is what is used in code and stored in you collections.
You can set the labels and values through code of a radio group.
https://www.wix.com/corvid/reference/$w.RadioButtonGroup.html#options
Set the list of options for a radio button group
$w("#myRadioGroup").options = [ {"label": "Who's on first!", "value": "first"}, {"label": "What's on second", "value": "second"}, {"label": "I Don't Know is on third", "value": "third"} ];
You might find it easier to simply just us a single checkbox and set the value for it and then check to see if it is checked or not etc.
https://www.wix.com/corvid/reference/$w.Checkbox.html
https://www.wix.com/corvid/reference/$w.Checkbox.html#checked
https://www.wix.com/corvid/reference/$w.Checkbox.html#value
I have read all the references you are siting. My issue is that the database field value is not passing from the text element to the radiogroup value. I am only getting the text itself...and even then it submits a blank entry.
Is there a way to directly assign a database field value to a radiogroup option?
Have read here too.
https://support.wix.com/en/article/adding-and-setting-up-radio-buttons
Radio Buttons
Radio Buttons allow users to select one of a predefined set of options.
Radio buttons have a label (text displayed on your page) and a value (data stored in your collection).
Have a read of radio button groups here.
https://support.wix.com/en/article/setting-labels-and-values-for-radio-buttons-and-dropdown-lists
https://www.wix.com/corvid/reference/$w.RadioButtonGroup.html
Each radio button in the group needs a label that the user sees and also a value that gets added to your dataset.
This is explained on the first link in the example box.
https://www.wix.com/corvid/reference/$w.RadioButtonGroup.html#value