Nibble

A look at prevalue sources in umbraco contour

After the post about data sources in contour this post outlines another feature of contour, prevalue sources.

A prevalue source allows you to setup a source that you can hook to a field type that supports prevalues (dropdown, checkbox list, radio button list).

Let’s say we have an existing database table that has a lists of all countries, well instead of having to setup these countries manually when we want a countries dropdown we can create a new prevalue source and link this to our field.

So when we take a look at the contour section you’ll notice 3 trees (forms, data sources and prevalue sources)

image

So it’s obvious that we’ll be managing the prevalue sources in the prevalue sources tree.

Let’s say I have the following database, containing a table that has all countries in it

image

And now I want to use this table as a source for a countries dropdown.

First I would create a new prevalue source and call in Countries, once that has been created I’ll choose the sql database prevalue source type (since I’m getting the values from a db table)

image

As you can notice by default there are 2 SQl Database types, ‘SQL Database’ and ‘SQL Database (read only)’. If you choose the normal one we will also be able to update / delete and create new prevalues (which will update the prevalue source, so the db table in this case).

Once we select a type the type specific settings will load and we”ll need to fill these in

image

In the case of the SQL Database prevalue source type we’ll need to setup

  • Connectionstring to the db
  • Table name
  • Name of the column containing the key
  • Name of the column containing the value (that will be displayed)

Once these are filled in and the prevalue source has been saved succesfully we are ready to use the newly configured prevalue source.

When we now add or edit a field that supports prevalues (dropdownlist, radiobutton list, checkbox list)

We’ll be able to choose the type

by choosing a prevalue source ‘so anything else then standard’ we’ll link the field to the source

image

That’s it now our dropdown will list all items in the table.

In this example I used the sql database prevalue source type but there are also some other default prevalue source types and it’s of course also possible to plug in your own custom types!

2 Comments so far

  1. Anz on March 17th, 2011

    I am new to Umbraco and your blogs are great help..

    Thanks
    Anz

  2. Chris on August 7th, 2012

    I’m setting up a Contour form and come across an issue.

    We will have the normal fields (name, message, etc.) but also want a drop down email with a list of senior leadership names. These senior leadership contacts will be the ones that receive the email once submitted. Can you please explain in detail the best way to do this? xslt edits, prevalue sources with workflow changes, or something else? I’ve done my fair share of researching and I’m new to Umbraco. Please help.

    Thanks

Leave a Reply