Default Values

Static Values

A static default is set when the the form is first opened.

Note

To add a staric default; place the default value in the default column without using quotation marks.

Static Default:
type name label default
select_one food_group food_group Which food group was this? legumes

In the above example the default value for the select one question is set to legumes.

Special Static Defaults

You can use one of these special values in the default column.

Special Static Default Values:
default comment
now() Sets a date or date-time question type to the current date/time

Referring to Preloads

Because a static default value is set when the form is first opened there is no point referring to the answers to other question in order to set the default value. For that you will need to use a dynamic default. However you can refer to a preload. So for example you may specify a preload to get the users name and you can then use that preload value in a static default.

Using Preloads in Static Defaults:
type name label default
username uname    
text uname_confirm Confirm your name ${uname}

Dynamic Defaults

A dynamic default value is specified in the calculation column for a question. Hence you can set the initial answer to a question based on the answer to a preceeding question.

Warning

Calculations in FieldTask are updated every time their source changes and also just before the survey is saved. This can cause lots of issues when using them to set default values. For example if you had a dynamic default calculation of ${number_girls} to set the default value for a question on how many girls go to school then the answer (to how many girls go to school) will be reset back to the default value when the form is saved.

To avoid the problem of recalculation of defaults when the form is saved wrap the calculation in the once() function:

once(${number_girls})

Now the default value is set when the question is shown. Once the answer has been set then it will not be changed again by the calculation.

Note

Webforms does not have the above issues with dynamic defaults and you should not wrap the default calculation in the once() function.

Dynamic Images

Images are a special case because you can dynamically specify an image URL as the default value of a question. If the Android device or WebForm is online this image will then be downloaded. One application of this might be if you had an image question with an appearance of annotate. The image URL can be selected from a list of drawing schematics, the selected image would then be downloaded and the user would be able to annotate the selected schematic.

Use a get_media() function to download the required URL. There are some differences between the way WebForms and FieldTask work.

WebForms

For webforms the get_media() function takes 2 parameters. The first is the URL to retrieve and the second one is the path to the question that should receive the URL. This is different from the every other use of dynamic defaults in that the calculation places in the result in the specified question. Hence you don’t need to have anything in the calculation column of the target question:

get_media(${q1}, '/main/q3')

Note

For the second parameter you cannot use the ${} notation. Paths to questions always start with ‘/main’ and then continue with the names of groups and questions each separated by a ‘/’

Example survey for Dynamic Images (WebForm version)

FieldTask

Only one parameter is required for get_media() which is the URL of the image. Then the calculation question is specified in the calculation column of the target question:

calculate  q2   if(string-length(${q1}) > 0, get_media(${q1}, '/main/q3'), '')
image      q3   once(${q2})

Remember the dynamic default value is wrapped in a once() function so that it only gets set once.

Example survey for Dynamic Images (FieldTask Version)

Security Considerations

Security controls on the server holding the images may prevent their access within a form. So unless they are on a completely open server you will need to consider access permissions and CORS settings.

Alternatively if you are accessing images collected by other surveys on the same Smap server then you can use the Smap security controls (projects, RBAC) to control access.