New page: == Description == This property existed in both questionnaire template's properties and question's properties . *Setting for questionnaire : Image:QnaireRequired.JPG *Setting for q... |
No edit summary |
||
Line 33: | Line 33: | ||
*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). | *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 == | |||
=== This example shows how to use the Required property of grid question and apply it to related sub question === | |||
<source lang="csharp" line="1"> | |||
// Apply the required property if set | |||
QuestionProperty requiredProperty = q.GetProperty(PropertyType.Required); | |||
if (requiredProperty != null && !string.IsNullOrEmpty(requiredProperty.Value)) | |||
{ | |||
// Parse the property's value into ranges | |||
Ranges requiredRanges = new Ranges(requiredProperty.Value); | |||
// For each range run through the integers contained in the range | |||
// and set the required property to true | |||
foreach (Range r in requiredRanges) | |||
for (int j = r.From; j <= r.To; j++) | |||
//Tho : this if expression is to make sure that we only take valid | |||
//sub question index . Some old questionnaire template has invalid property value | |||
if ( j>-1 && j < q.subQuestions.Count) | |||
q.subQuestions[j].Required = true; | |||
} | |||
// Apply the not required property if set | |||
QuestionProperty notRequiredProperty = q.GetProperty(PropertyType.NotRequired); | |||
if (notRequiredProperty != null && !string.IsNullOrEmpty(notRequiredProperty.Value)) | |||
{ | |||
// Parse the property's value into ranges | |||
Ranges notRequiredRanges = new Ranges(notRequiredProperty.Value); | |||
// For each range run through the integers contained in the range | |||
// and set the required property to false | |||
foreach (Range r in notRequiredRanges) | |||
{ | |||
if (r.To >= q.SubQuestions.Count) | |||
r.To = q.SubQuestions.Count - 1; | |||
for (int j = r.From; j <= r.To; j++) | |||
//Tho : this if expression is to make sure that we only take valid | |||
//sub question index . Some old questionnaire template has invalid property value | |||
if (j > -1 && j < q.subQuestions.Count) | |||
q.subQuestions[j].Required = false; | |||
} | |||
} | |||
</source> | |||
=== This example show how to apply Required property of questionnaire template to question and register it to client side === | |||
<source lang="csharp"> | |||
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; | |||
//... | |||
} | |||
</source> | |||
=== This example shows how to apply Required property of question register it to client side === | |||
<source lang="csharp"> | |||
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; | |||
//... | |||
} | |||
</source> | |||
[[category:Technical guidelines]] | [[category:Technical guidelines]] |
Revision as of 10:35, 7 April 2009
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
// Apply the required property if set
QuestionProperty requiredProperty = q.GetProperty(PropertyType.Required);
if (requiredProperty != null && !string.IsNullOrEmpty(requiredProperty.Value))
{
// Parse the property's value into ranges
Ranges requiredRanges = new Ranges(requiredProperty.Value);
// For each range run through the integers contained in the range
// and set the required property to true
foreach (Range r in requiredRanges)
for (int j = r.From; j <= r.To; j++)
//Tho : this if expression is to make sure that we only take valid
//sub question index . Some old questionnaire template has invalid property value
if ( j>-1 && j < q.subQuestions.Count)
q.subQuestions[j].Required = true;
}
// Apply the not required property if set
QuestionProperty notRequiredProperty = q.GetProperty(PropertyType.NotRequired);
if (notRequiredProperty != null && !string.IsNullOrEmpty(notRequiredProperty.Value))
{
// Parse the property's value into ranges
Ranges notRequiredRanges = new Ranges(notRequiredProperty.Value);
// For each range run through the integers contained in the range
// and set the required property to false
foreach (Range r in notRequiredRanges)
{
if (r.To >= q.SubQuestions.Count)
r.To = q.SubQuestions.Count - 1;
for (int j = r.From; j <= r.To; j++)
//Tho : this if expression is to make sure that we only take valid
//sub question index . Some old questionnaire template has invalid property value
if (j > -1 && j < q.subQuestions.Count)
q.subQuestions[j].Required = false;
}
}
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;
//...
}