About Radio Button and Check box

Now I am typing correct answer but i want like I want to select answer if one answer then it must come in radio button to  select the correct answer and if multiple answer means check box must to select multiple answer and in data all questions are mixed with single answers questions and multiple answers questions. so how to give radio button and check box

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Just like Harshit suggested you need check for the Choices, I wrote a simple expression use it as reference for your implementation

    a!localVariables(
      local!questionsWithAnswers:{
        a!map(
          Question:"Where is TajMahal Located",
          Options:{"Agra","Pune","Vizag","Delhi"},
          Answer:{"Agra"}
        ),
        a!map(
          Question:"Cities in India",
          Options:{"NY","Paris","Vizag","Delhi"},
          Answer:{"Vizag","Delhi"}
        )
      },
      local!selectedAnswers,
      a!forEach(
        items: local!questionsWithAnswers,
        expression: {a!richTextDisplayField(
          value: concat(fv!index,".",fv!item.Question),
        ),
          if(
         count( fv!item.Answer)=1,
         a!radioButtonField(
           choiceLabels: fv!item.Options,
           choiceValues: fv!item.Options,
         ),
         a!checkboxField(
           choiceLabels: fv!item.Options,
           choiceValues: fv!item.Options
         )
         
        )}
      )
    )

  • If the values we are taking from cdt not from record then

  • 0
    Certified Senior Developer
    in reply to akhilap

    It would be the same instead of using a map inside the local variable you call your rule. If it is a record you would have recordType references.
    In the below code the "isMultiple" defines whether the question has multiple answers or not.  I would recommend having two different data bases for questions and Answers. where in the Questions Table you will have a field to Identify whether your question has Multiple answers or a single one. In the answers Data base table you will have a field of the Primary key of Questions Table. 

    a!localVariables(
      local!question: rule!CDT_myQuestions(isActive: true()),
      local!answers: rule!CDT_myAnswers(isActive: true()),
      a!forEach(
        items: local!question,
        expression: a!boxLayout(
          label: fv!item.Question,
          contents: {
            a!textField(
              value: if(
                fv!item.isMultiple,
                "Multiple Choice",
                "Single Choice"
              ),
              readOnly: true
            ),
            if(
              fv!item.isMultiple,
              a!checkboxField(
                choiceValues: index(
                  local!answers.id,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                choiceLabels: index(
                  local!answers.Answers,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                
              ),
              a!radioButtonField(
                choiceValues: index(
                  local!answers.id,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                choiceLabels: index(
                  local!answers.Answers,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                
              )
            )
          },
          marginBelow: "MORE",
          style: "ACCENT"
        )
      )
    )




Reply
  • 0
    Certified Senior Developer
    in reply to akhilap

    It would be the same instead of using a map inside the local variable you call your rule. If it is a record you would have recordType references.
    In the below code the "isMultiple" defines whether the question has multiple answers or not.  I would recommend having two different data bases for questions and Answers. where in the Questions Table you will have a field to Identify whether your question has Multiple answers or a single one. In the answers Data base table you will have a field of the Primary key of Questions Table. 

    a!localVariables(
      local!question: rule!CDT_myQuestions(isActive: true()),
      local!answers: rule!CDT_myAnswers(isActive: true()),
      a!forEach(
        items: local!question,
        expression: a!boxLayout(
          label: fv!item.Question,
          contents: {
            a!textField(
              value: if(
                fv!item.isMultiple,
                "Multiple Choice",
                "Single Choice"
              ),
              readOnly: true
            ),
            if(
              fv!item.isMultiple,
              a!checkboxField(
                choiceValues: index(
                  local!answers.id,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                choiceLabels: index(
                  local!answers.Answers,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                
              ),
              a!radioButtonField(
                choiceValues: index(
                  local!answers.id,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                choiceLabels: index(
                  local!answers.Answers,
                  wherecontains(fv!item, local!answers.questionId),
                  null
                ),
                
              )
            )
          },
          marginBelow: "MORE",
          style: "ACCENT"
        )
      )
    )




Children