Introduction

The latest How To topics are available in the K2 Five User Guide or the K2 Cloud User Guide’s How to section.

This Knowledge Base article describes how to specify one or more default values using a SmartObject as the data source of a Drop-Down List control.

Audience
  • Developers
  • View Designers
Required Knowledge
  • Views
  • Rules
  • Controls

Implementation Details

A Boolean (Yes/No) property can be configured that will be used as the Default Value in the Data Source Configuration popup when using a SmartObject as the data source of a control such as the Drop-Down List control. The value(s) set to true for the Boolean property will be returned to the control at runtime and be displayed according to the control used.

Image

Image

Image

For more detailed information see the following topic in the K2 smartforms User Guide:
K2 smartforms > K2 Designer > Controls > Drop-Down List control

Example Scenario

In the scenarios below we will use SmartObjects called Country and City. Each Country will have two cities of which one will be the default city. We will create two scenarios; one where a Drop-Down List returns all cities and selects the first default city; and one where the City Drop-Down List will be filtered based on the value of the Country, and the default city will be selected.
Follow the steps below to set up the scenarios:

Scenario 1 - Drop-Down List returns all cities and selects the first default City:

  1. Create the Country and City SmartObjects as shown below:

    Image

    Image

  2. Create an association on the City SmartObject as shown below:

    Image

    Image

  3. Create Editable List Views for both SmartObjects.
  4. Create some records for the Country SmartObject.

    Image

  5. Create some records for the City SmartObject. Remember to create one default city for each country.

    Image

  6. Create an Item View using the City SmartObject. Drag a Drop-Down List control onto the canvas and use the City SmartObject as the data source for the control. Select the Default property as the Default Value.

    Image

  7. Click OK and Finish the View.
  8. Run the View. Note that New York is selected as the default as it’s the first default city in the list returned. (the list is returned in alphabetical order)

    Image

Scenario 2 - We now want to create a dependent drop down scenario, where the City Drop-Down List will be filtered based on the value of the Country, and the default City will be selected. Use the same SmartObjects created in scenario 1 and then follow the steps below:

  1. Create an Item View from the City SmartObject.
  2. Drag the Country and City properties onto the canvas and change the City control to a Drop-Down List.
  3. Configure the data source of the City Drop-Down List as shown below:

    Image

  4. Click OK and Finish the View.
  5. Run the View. Select USA for example. Note how the City drop-down is filtered and the default is selected.

    Image