Displaying Data as Read-Only

Sometimes the answers to some questions need to be displayed to the user in such a way that they cannot be modified. This is already the case on summary pages where users can review the answers and use the back button or edit links to modify them.

On a question page, a "read-only" boolean attribute can be set to true indicating that all the questions displayed on the page will not be editable.

A more sophisticated mechanism exists: "read-only-expression" attributes can be used on different script elements (sections, all types of pages, clusters, questions and list questions). If the expression evaluates to true, this will apply to all the questions contained in the element. At its simplest, the expression will be "true" if the element needs to be unconditionally read-only. On a summary page, the result is that add, edit and delete links are not displayed.

In the case of read-only-expression defined for cluster, question and list question script elements, if any of the questions referenced in the expression are on the same page as the script element the script element is then dynamically enabled or disabled as opposed to just being read-only. This means that questions will be enabled and disabled as the user changes answers to other questions on the page. Where the read-only-expression of a cluster references a question on the same page all the questions contained in the cluster will be enabled and disabled. This dynamic feature of IEG requires that JavaScript is enabled in the browser. The expressions to dynamically enable and disable questions may not refer to custom functions, as the expressions are evaluated without making a server call.

Dynamic read-only-expressions may also refer to questions on the same page that are themselves dynamically enabled and disabled. This creates a cascading dependency between questions. Care should be taken when defining expressions with cascading dependencies as IEG does not take into account whether the questions referred to in the read-only-expression is enabled or not, just the value of the question. This may be confusing for the user as it may not be apparent what is controlling the enabling and disabling of a question.

When a question is displayed if the corresponding Datastore attribute has a value it will be displayed even if the question is initially disabled. The question may then be enabled by the user and the user may change the answer. If the question is disabled its value will set back to the value it had when initially displayed. When a page is submitted the Datastore attribute will not be updated unless the question is enabled. Therefore if the page is redisplayed the original value of the Datastore attribute will be displayed again.

It is not possible to mark a question as mandatory if it also has a dynamic read-only-expression on the question itself or one of its parent elements.

Dynamically enabling and disabling script elements is not supported on Relationship Pages.

The information gathered in loops can be displayed on summary pages using lists, but it is also possible to use this list construct on regular pages without the need to specify a read-only-expression in one of the elements wrapping the list. The only difference with summary lists is that links are not allowed.

Another possibility is to make a whole script read-only. This is useful, for example, if a case-worker needs to review a script without being able to change any of the answers. The script is set to read-only through the IEGRuntimeAPI by setting a read-only flag on the script execution, as shown below:

Figure 1. Setting the read-only flag on a script execution
...
//Set read only flag.
IEGRuntime runtimeAPI = new IEGRuntime();
IEGScriptExecutionID runtimeExecID = new IEGScriptExecutionID();
runtimeExecID.executionID = execution.getExecutionID();
IEGReadOnlyFlag readOnlyFlag = new IEGReadOnlyFlag();
readOnlyFlag.readOnlyFlag = true;
runtimeAPI.setReadOnlyFlag(runtimeExecID, readOnlyFlag);
...