Hi Steven!
So something like this…
datastore questions
question_id
question_text
datastore answer_options
answer_id
question_id
question_answer (concatenation of question_id and answer_id)
answer_text
[Add Question Button] dmx-on:click"questions.insert({question_id: questions.data.count()})"
variable this_question_id.setValue(question_id)
repeat questions.data
<input id="this_question" ... dmx-on:update="questions.update({question_id: this_question_id.value}, {question_text: this_question.value})".../>
[Add Answer Button] dmx-on:click"answers.insert({question_id: this_question_id.value, answer_id: answers.data.where(question_id=this_question_id.value).count(), question_answer: this_question_id.value+' '+answers.data.where(question_id=this_question_id.value).count()})"
repeat answers.data.where(question_id=this_question_id.value)
<input id="this_answer" ... dmx-on:update="answers.update({question_answer: this_question_id.value+'_'+answe_id}, {answer_text: this_answer.value})".../>
It’s the end of the day, so I may have some of the syntax a bit wrong! But here are the key points:
- Datastores for questions and answers
- In this simple example, question_id/answer_id are just the next sequential number from the existing count. You may need a .count()+1 depending how you work and something more sophisticated to insert and delete questions/answers.
- You are updating the answer datastore on the value of question_id AND answer_id, and the only way to do that right now is to combine the two into another field
question_answer
. So if question_id=5 and answer_id=2 then question_answer=“5_2”. - Each datastore’s question/answer text is updated using
dmx-on:update
Drop me a line if any of it is confusing!
Good luck,
Antony.