Module 4
Add code lists manually, programmatic and dynamically
In this module you’re expanding the application you made in the previous modules to support more of the requirements of the municipality of Sogndal.
Topics covered in this module:
- Code lists/Options
- Dynamic
Tasks
In many applications there is a need to provide the user with a set of response options for a data field.
The answer options are referred to as code lists or options.
In Altinn Studio this is supported in the form of radio buttons, checkboxes and dropdown lists.
There are three ways to set up code lists in Altinn today
- Directly on the component through Altinn Studio or manually in FormLayout.json*
- In a static json-file referred to in the component
- Programmatically through application logic (only available for radio buttons and check boxes)
In this task, you will get to try out all three ways to set up a code list.
The municipality of Sogndal wishes to collect information on the newcomers working situation. Some of the data they wish to collect is which sector and industry the newcomer works in, and how many years the newcomer has been active in the workforce.
In Altinn Studio
Create a new form page to collect data about working conditions
Set up a radio button component for Sector. Create the answer options Offentlig
and Privat
manually.
Set up a check box component for Industry.
Choose Kodeliste as method for adding checkboxes and add Kodeliste ID industry
The rest of the setup for this component is done locally
Set up a dropdown list for Years in work force
Add Kodeliste ID years-in-work-force
The rest of the setup for this component is done locally
Commit and Push your changes to master,
and Pull the changes to your local development environment.
In Local Development environment
The municipality of Sogndal has created a code list for industries. Download the file and place it correctly in the repository.
Set up the values in the code list for Years in work force directly in a new C# class.
Answer options:
Label | Data value |
---|
0 - 5 years | 0-5 |
5 - 10 years | 5-10 |
10 - 20 years | 10-20 |
20+ years | 20+ |
Verify that all code lists works as expected.
Useful documentation
Knowledge check
- What is the difference between static and dynamic options?
- What will the area of use be for secured dynamic options?
In some cases the values displayed in a code list may be attached to a different field in the form.
The municipality of Sogndal wants the list of industries to choose from to be personalised based on which sector the user works in.
Requirements from the municipality
We want the user to be presented with a different set of options for the industry choice based on which sector they work in.
Useful documentation
Knowledge check
- If a list of options is set up with mapping towards the data model - what happens when the field in question changes value?
- What happens with the chosen value on a field connected to an option-list that is retrieved over again from the server side?
Summary
In this module you have set up the dropdown list, radio button and checkbox components and added options for them manually, programmatically and dynamically.
The service should run on your local computer with local test and it should be possible to select the expected option from each component.
Remember to push your local changes, so that they are available in Altinn Studio when you’re happy with them
Solution
If you did not manage to complete all the steps, we have an example solution that you can use as inspiration.
