Example of simplified buttons partial view
In the previous example we showed how to create a new template. In this one we will show how create a template that replaces one of the partial views from Default.
The template logic can be defined in the views or through changes in the javascript. As a general rule, it's convenient to only change the views if the structural changes are big or the code would be heavily simplified.
As in previous examples we will use as a starting point the questionnaire:
*QUESTION 10 *CODES 61L1
Do you own a smartphone?
1:Yes
2:No
*END
Which generates the output:
In this example we are going to create a template that only allows to go to the next question independently of the survey configuration (won't have back, clear, pause or custom options).
Steps
- The first thing that we have to do, is to locate where the buttons are generated.
As we can see in Views, the _Buttons
partial view is directly part of the Screen
view.
If we open the Screen.cshtml
file, we can effectively see how it's referenced directly.
<div id="segment-end">
@{ Html.RenderPartial("Buttons", Buttons(Model)); }
</div>
Once we open the _Buttons.cshtml
file, we can see how it goes through all the buttons in the model and creates an input
element for each of them.
@model IEnumerable<NipoSoftware.Nfield.Interviewing.Contracts.Data.Button>
<div id="navigation-container">
@foreach (var button in Model)
{
<input type="submit" name="button-@button.Name.ToLowerInvariant()" value="@button.Text" class="button button-@button.Name.ToLowerInvariant()" />
}
</div>
To achieve our objective, we create a copy of the
_Buttons
file into a different folder.As we want to minimize the number of changes, we can add an additional
if
condition in theforeach
, which would lead to:
@foreach (var button in Model)
{
if(button.Name.ToLowerInvariant() == "next"){
<input ... />
}
}
- As in the previous example, we generate a
NextOnlyTemplate.zip
file with the view in the root and we update the ODIN script with that template:
*TEMPLATE "NextOnlyTemplate"
*QUESTION 10 *CODES 61L1
Do you own a smartphone?
1:Yes
2:No
*END
The new view will only contain now the next button