159
Views
7
Comments
Radio Group in a table

I have created a table that contains a radio group next to each row. I want to be able to select and save different answers per row. Currently, when I select something, the same answer is selected for all rows and only the first question-answer pair is saved.  What do I need to do to be able to select and save different answers?

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @shooouse ,

so this is a variation on the very common forum question 'why do all checkboxes get selected when I click one in the list/table'

So, your radio group is an html element for entering a value, just like others, e.g. input or dropdown.  You attach the radio group widget to a variable, this is the "Variable" property of the radio group.

Just placing your radio group inside a list or table widget is not enough to be able to remember/hold the selected option for each row separately.  If you have chosen a single local variable for this 'Variable' property of your radio group widget, all instanced will set/show that same single local variable.

You need to have an 'Antwort' attribute inside your list variable (aggregate or local, whatever you have), and use that one as the 'Variable' property of your radiogroup.  

For aggregates, it can either already be there, because it is part of the entities you are retrieving, or you need to add it by adding a calculated column to the aggregate.  

If you are using a list variable, you have to make sure the list structure has such an attribute.

Dorine


UserImage.jpg
Kay Lun

Hi shooouse,

beside the method that @Dorine Boudry suggested, the other way would be create a block widget for those radio group, cuz every block widget would have their own logic, so inside the block widget, you could reuse the local variable to save the selected item.

Just have to rememebr, you still need an event to pass the select item back to the parent screen for further usage.

Hope this could help :)

UserImage.jpg
shooouse

Hi @Kay Lun ,

Thank you very much for your answer. I have created a block and now I can select different answers per row. However, I am not able to save the answers. I used to create blocks where I only passed one value to the parent screen - maybe that's why I can't do it now, because I'm trying to pass and save multiple values at once?

2021-09-06 15-09-53
Dorine Boudry
 
MVP


pushing the radio group down into a block, doesn't make your fundamental problem go away, it only hides it. In a way the block adds complexity of extra communication between block and parent screen in 2 directions(input parameter and event), without solving anything.

Your fundamental problem is still that you need to have some space in your list variable (either aggregate result or local list) representing for each item of the list what the chosen option is.

UserImage.jpg
Kay Lun

Hi shooouse,

sorry I forgot to mention that, you have to turn the whole list item into a block, so you could reuse the block widget in the list, and depends on the complexity you could decide whether you should use block for the radio group or not. 

And @Dorine Boudry was right, the problem is that, you need a key / index to determine the selected radio is belong to which row of the list.

When you convert the list item into a block, then use it in the list, the problem still exist if you haven't do it right.

So try to make it simpler, assume you have a local variable to store the selected radio for each row of Frage, which should be a List Structure type, every time you select the radio, you will append the selected value into the List, you need to pass the Frage row key into the list together

for example:

Hope this could give you a better idea on your question :)

UserImage.jpg
shooouse

Hi @Dorine Boudry  and @Kay Lun ,

I tried to implement my solution with the help you both gave. In the end, I stuck with the block and created a "Submit" button for each row that linked the answers to the questions and I was able to create a list. However, I sometimes got wrong values (mainly because I couldn't set it to overwrite the already saved answer if the user changed his answer), so I had to ask my colleague to help me. He created a block for the answers and inserted it into a second block with the questions table. He stores the answers on the fly in a table that can only hold one answer per question. 
Anyway, maybe in my spare time I will come back to the topic and try to implement it the way I started with the inputs you gave. 

Thank you for your replies, I really appreciate them! 

UserImage.jpg
Kay Lun

Remember in the end, you just have to figure out how the data store and reuse in OS, after you understand the concept, you should be able to figure out what's the best way to deal with the problem. Hope someday you will find your own implementation.

Cheers :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.