function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mlueckemluecke 

Dynamic multiple Radiobuttons

I hope, anyone has a idea how to solve this.
I have a parent object with multiple child objects. The child objects create some kind of timetable, e.g. child1 and child2 start at 9 am and end at 10 am and child3 and child4 start at 10am and end at 11 am. In addition it may occur that there is one session longer. Like this:
example session timetable

The user should not be able to select parallel sessions or select the longer session and one of the parallel sessions. I will get the display done but I don't know how to save the selections. I need to create a link between the attendant and the selected sessions - generally I would work with Lists/Maps. How can I bind the selections to List elements?
I appreciate your help!
KRayKRay
mluecke, This is a two parter but I can provide some feed back.

Parallel (Short) Sessions, name the radio buttons the same name, e.g. name="row1RadioBtns". This will prevent both sessions from being selected at the same time.

Long Session, You can use Javascript to check if any other sessions at that time are checked. You can use onblur or onclick. Post your code and I can provide more help, if needed.
mlueckemluecke
Thank you for your reply.
Still got more questions: I do not know how many sessions/session timeslots will be there (the image is just an example) and I would like to save all of the selected values from the radiobuttons. In addition I do not know whether there is a longer session or not (usually there will be NO long session). So I have n sessions, some parallel to each other. My approach would be to create a List (or a Map) of List<SelectOption> in the controller, where each List<SelectOption> is one timeslot (starting time) and to iterate with <apex:repeat> through the list of lists to create the radiobuttons for each timeslot. How to save the selected values of n <apex:selectRadio>? Is it possible to assign a List to the value-attribute of selectRadio and a new entry will be created dynamically? Or do I have to create up to 100 single variables to hold the selected value?
I'm at the beginning of this project, so I don't have any code to provide yet. It will be a three or four step registration process and I'm working on step two (just a simple name, company etc. form).
mlueckemluecke
Has nobody an idea?
mlueckemluecke
I came this far: I have an workflow to set the sessions name with start and end datetime, so parallel sessions have the same name. When it comes to the session selection, I create a map of list<selectOption>:
public Map<String, List<SelectOption>> getSessionOptionsByName()
	{
		Map<String, List<SelectOption>> SessionOptionsByName = new Map<String, List<SelectOption>> ();
		for(Session__c session : [SELECT Id, Name, Startzeit__c, Endzeit__c, Session_Name__c, Location_Raum__c FROM Session__c WHERE Event__c = :selectedEvent ORDER BY Name])
		{
			if(SessionOptionsByName.containsKey(session.Name))
			{
				SessionOptionsByName.get(session.Name).add(new SelectOption (session.id, session.Session_Name__c));
			}
			else
			{
				// this.selectedSessions.add(Session.Id);
				List<SelectOption> tempList = new List<SelectOption>();
				tempList.add(new SelectOption (session.id, session.Session_Name__c));
				SessionOptionsByName.put(session.Name, tempList);
			}
		}
		system.debug(sessionOptionsByName);
		return SessionOptionsByName;
	}
and I create a list of Ids to hold the selected sessions:

public List<Id> selectedSessions{get;set;}
selectedSessions = new List<Id>();

On the page I iterate over the map and create multiple selection lists:
<apex:form >
				<table border="1">
					<apex:variable var="cnt" value="{!0}" />
					<apex:repeat value="{!SessionOptionsByName}" var="sessionName">
					<tr>
						<!-- <td>{!SessionsByName[sessionName].Startzeit__c}</td><td>{!SessionsByName[sessionName].Endzeit__c}</td> -->
						<apex:selectRadio value="{!selectedSessions[cnt]}">
						<apex:actionSupport event="onchange" rerender="selectionDisplay" />
							 <td><apex:selectOptions value="{!SessionOptionsByName[sessionName]}" /> &nbsp;</td>
						</apex:selectRadio><br/>
					</tr>
					<apex:variable var="cnt" value="{!cnt+1}"/>	
					{!cnt}	
					</apex:repeat>
					<td style="text-align:right;">
						<br/><apex:commandButton action="{!SessionSelection}" value="{!$Label.Weiter}" styleClass="ab"/>
					</td>
								
				</table>
			
			</apex:form>
When I leave the selectedSessions list empty, I receive an  error:
Subscript is invalid because list is empty

So I prefill the list in the getSessionOptionsByName()-Method, for the page to render properly. But, whenever I change the session selection, the selectedSessions list receives a new entry instead of replacing the previous selection and when I go on to save the selected sessions to the attendant, ALL sessions which where previously selected (no matter whether they are still selected) are in the list.

Can anybody help with this? I only want to save the current selection, not all ever selected values.