Forms
You can use styles to lay out interview pages so that they replicate printed forms that you already use in your organization. While some basic familiarity with templates is handy, much of the skill in laying out forms lies in knowing how to use horizontal alignment to determine the relative positions of items on a line. This topic gives some examples that you can use as the basis for designing your own forms.
Displaying two or more questions on the same line
The output for this example is:
Title & last name on one line with first name & middle initials on the next line
It was created by defining the basic questions in the metadata section and placing the following code in the routing section:
' Template for question text & response controls on same line.
IOM.Questions[..].QuestionTemplate = "styles2.htm"
' Field width for question texts
Title.Label.Style.Width = "5em"
FirstName.Label.Style.Width = "5em"
Initials.Label.Style.Width = "6em"
LastName.Label.Style.Width = "5em"
' Response controls to right of question texts
Title.Style.ElementAlign = ElementAlignments.eaRight
FirstName.Style.ElementAlign = ElementAlignments.eaRight
Initials.Style.ElementAlign = ElementAlignments.eaRight
LastName.Style.ElementAlign = ElementAlignments.eaRight
' Put LastName/Initials on same line as previous element ...
Initials.Label.Style.ElementAlign = ElementAlignments.eaRight
LastName.Label.Style.ElementAlign = ElementAlignments.eaRight
' ... with this space between the two
Initials.Label.Style.Indent = 2
LastName.Label.Style.Indent = 2
' Width for LastName/Initials input boxes
LastName.Style.Width = "13.5em"
Initials.Style.Width = "5em"
' Drop-down selection list for Title
Title.Style.Control.Type = ControlTypes.ctDropList
FullName.Ask()
The comments in the code explain what each set of statements does. However, there are some additional points to note.
▪Statements are grouped by function rather than by question name, so all the statements to do with placing response controls next to question texts are together. You could reorganize the statements so that the statements are grouped by question name, if you find this approach more logical. As long as all requirements are covered it does not matter what order they are defined in. The only rule is that the .Ask statement that displays the question comes last.
▪The widths of the input boxes for LastName and Initials have been specified to ensure that the ends of the boxes line up. Working out the measurements is done by trial and error as you test your script.
▪The maximum response lengths for FirstName, LastName, and Initials were set in the metadata at 40, 40, and 5 respectively to ensure that the input boxes were displayed as single-line boxes. Lengths greater than 40 characters result in input boxes showing six lines of 34 characters.
The metadata equivalent of this routing code is as follows:
Title1 "Title"
labelstyle(width="5em")
style(elementalign="right", control(type="droplist"))
categorical [1..1]
{Ms, Miss, Mrs, Mr};
FirstName1 "First Name"
labelstyle(width="5em")
style(elementalign="right")
text [0..40];
Initials1 "Middle Initials"
labelstyle(elementalign="right", indent=2, width="6em")
style(elementalign="right", width="5em")
text [0..40];
LastName1 "Last Name"
labelstyle(elementalign="right", indent=2, width="5em")
style(elementalign="right", width="13.5em")
text [0..40];
FullName1 "" page(Title1, LastName1, FirstName1, Initials1);
The question sub-template for this example is:
<mrSubTemplate>
<mrData QuestionElement="Label"/>
<mrData QuestionElement="Controls"/>
</mrSubTemplate>