Business logic of Require property in Questionnaire Template
<accesscontrol>Main:MyGroup</accesscontrol>
Contents
- 1 Description
- 2 Business logic
- 3 Working with Required property in .NET side
- 3.1 This example shows how to use the Required property of grid question and apply it to related sub question
- 3.2 This example show how to apply Required property of questionnaire template to question and register it to client side
- 3.3 This example shows how to apply Required property of question register it to client side
Description
This property existed in both questionnaire template's properties and question's properties .
- Setting for questionnaire :
- Setting for question (non-Grid question)
- Setting for question (Grid question)
- Using in .NET
CatGlobe.Domain.Questionnaires.PropertyType.Required
- Using in Java
Property.REQUIRED
Business logic
Required as Questionnaire's property
- If this property is checked , it means that all the question in the questionnaire template , which are not specified Required property explicitly , will require the users answer it and they can't go to another question without answering .
Behind the code : the template will has property REQUIRED with the property's value is "true" .
- If this property is unchecked , it means that all the question in the questionnaire template , which are not specified Required property explicitly,will not require users answer it.
Behind the code : the template will has property NOT_REQUIRE with the property's value is "true"
Required as Question's property
This property is inherited from the value of property Required in a questionnaire. However, a question can set anew for this property through its Required property, and this value is only applied to this question.
- Inherited from Required property of questionnaire template :
In this case the there is not both REQUIRED and NOT_REQUIRED property register in question's property (the existed one will be removed). So the question will inherited from the Required property of the questionnaire template]
- Required property is checked
In this case , the question will has REQUIRED property with the property's value is "true"
- Required property is unchecked
In this case , the question will has NOT_REQUIRED property with the property's value is "true"
- If the question is a GRID question ( single grid , multi grid , scale grid , text grid) , users need to define which sub questions will be required . The range will be save to the value of correlative property (REQUIRED or NOT_REQUIRED).
Working with Required property in .NET side
1 // Apply the required property if set
2 QuestionProperty requiredProperty = q.GetProperty(PropertyType.Required);
3 if (requiredProperty != null && !string.IsNullOrEmpty(requiredProperty.Value))
4 {
5 // Parse the property's value into ranges
6 Ranges requiredRanges = new Ranges(requiredProperty.Value);
7
8 // For each range run through the integers contained in the range
9 // and set the required property to true
10 foreach (Range r in requiredRanges)
11 for (int j = r.From; j <= r.To; j++)
12 //Tho : this if expression is to make sure that we only take valid
13 //sub question index . Some old questionnaire template has invalid property value
14 if ( j>-1 && j < q.subQuestions.Count)
15 q.subQuestions[j].Required = true;
16 }
17
18 // Apply the not required property if set
19 QuestionProperty notRequiredProperty = q.GetProperty(PropertyType.NotRequired);
20 if (notRequiredProperty != null && !string.IsNullOrEmpty(notRequiredProperty.Value))
21 {
22 // Parse the property's value into ranges
23 Ranges notRequiredRanges = new Ranges(notRequiredProperty.Value);
24
25 // For each range run through the integers contained in the range
26 // and set the required property to false
27 foreach (Range r in notRequiredRanges)
28 {
29 if (r.To >= q.SubQuestions.Count)
30 r.To = q.SubQuestions.Count - 1;
31 for (int j = r.From; j <= r.To; j++)
32 //Tho : this if expression is to make sure that we only take valid
33 //sub question index . Some old questionnaire template has invalid property value
34 if (j > -1 && j < q.subQuestions.Count)
35 q.subQuestions[j].Required = false;
36 }
37 }
This example show how to apply Required property of questionnaire template to question and register it to client side
foreach (QuestionnaireProperty p in Questionnaire.Properties)
{
switch (p.Type)
//Before inherited from Questionnaire properties , you must make sure that the question does not have both Required and NotRequired property
case PropertyType.Required:
if (Question.IsGrid())
{
int i = 0;
foreach (SubQuestion sq in Question.SubQuestions)
{
if (sq.Visible)
{
script.Append("// Require answer for ");
script.Append(sq.Question.Label);
script.Append("[");
script.Append(sq.GridNumber);
script.Append("]\n");
script.AppendFormat("quest.questions[{0}].required = true;\n", i++);
}
}
}
else
{
script.Append("quest.required = true;\n");
}
break;
case PropertyType.NotRequired:
if (Question.IsGrid())
{
int i = 0;
foreach (SubQuestion sq in Question.SubQuestions)
{
if (sq.Visible)
{
script.Append("// Not require answer for ");
script.Append(sq.Question.Label);
script.Append("[");
script.Append(sq.GridNumber);
script.Append("]\n");
script.AppendFormat("quest.questions[{0}].required = false;\n", i++);
}
}
}
else
{
script.Append("quest.required = false;\n");
}
break;
//...
}
This example shows how to apply Required property of question register it to client side
foreach (QuestionProperty p in Question.Properties)
{
// ....
switch(p.Type)
case PropertyType.NotRequired:
if (Question.IsGrid())
{
ranges = new Ranges(p.Value);
int i = 0;
foreach (SubQuestion sq in Question.SubQuestions)
{
if (sq.Visible && ranges.Contains(sq.GridNumber))
{
script.Append("// Not require answer for ");
script.Append(sq.Question.Label);
script.Append("[");
script.Append(sq.GridNumber);
script.Append("]\n");
script.AppendFormat("quest.questions[{0}].required = false;\n", i);
}
if (sq.Visible)
{
i++;
}
}
}
else
{
script.Append("quest.required = false;\n");
}
break;
case PropertyType.Required:
if (Question.IsGrid())
{
ranges = new Ranges(p.Value);
int i = 0;
foreach (SubQuestion sq in Question.SubQuestions)
{
if (sq.Visible && ranges.Contains(sq.GridNumber))
{
script.Append("// Require answer for ");
script.Append(sq.Question.Label);
script.Append("[");
script.Append(sq.GridNumber);
script.Append("]\n");
script.AppendFormat("quest.questions[{0}].required = true;\n", i);
}
if (sq.Visible)
{
i++;
}
}
}
else
{
script.Append("quest.required = true;\n");
}
break;
//...
}