I’m trying to create a page where a user chooses the correct answer out of two choices, for lots of different fields. For this, I need logic like “if answer a is ticked, answer b is disabled”, and lots of similar things. How can I best do this for a list of 100 or so questions? Is there a better way than just copy and pasting elements and changing each bit of logic individually?
FYI each question refers to a field of an entry in the database. Each field must be checked. Any help with this would be amazing thank you
The way I’d tackle this is, if you have 100 items that don’t relate to specific records in the DB, then generate a list of numbers for the number of rows/questions you need. Use a plug-in such as Toolbox (List of Numbers element) or Keith’s List Shifter (both free but Keith’s is Karmaware, buy him a coffee if you find it useful). You can then use the element which generates the numbers as the Data Source for a Repeating Group, set data type of the RG to Number. Put the elements you need in the row of the RG and it will get repeated 100 times. You’ll then need custom state lists to represent the information (questions/answers?) about each question. I hope this helps at least put you in the right direction.
Thanks @gazinhio! I’ll look into this
@gazinhio after having looked into this a bit more, that’s not quite what I was after. I need to be able to have each row in the repeating group display a field of the data type it holds. E.g. If the data type was fruit, which has entries apple, banana, orange, I’d need to set the repeating group to be apple. Then in each row I would like to display the fields of that datatype, so in this example an apple’s size, weight, colour etc. Is there a way to do this that will create as many rows as there are fields automatically?
I don’t think you’re gonna be able to do the whole thing dynamically eg read the number of data types off the DB and then pull the number of fields for each data type dynamically from the DB.
I would probably look at Option Sets to use as a reference for your data types. I would enter each data type that you want to include in your list as an option in the option set eg called _DataTypes and add an attribute to the option set for “No of Fields” and enter the number of fields into the attribute for each data set. You can then use the Option Set as the Data Source for the RG. Then use the No of Fields attribute of the selected option to determine the number of “Field” rows in the second RG for the fields. To do that use a number generator such as Keith’s List Shifter by setting the list shifter’s Number of Items to the No of Fields attribute of the selected option set. Then have your second RG (containing your fields) with a Data Type of Number and a Data Source pointing to the list shifter.
When a Data Type is selected in the first RG, pop the selected option in to a custom state and set the Number of Items on the List Shifter to the custom state’s No of Field attribute. That way you’ll have the right number of rows in your Fields RG based on the data type they select in the first.
Hope this helps.
This topic was automatically closed after 70 days. New replies are no longer allowed.