O'Reilly logo

Programming Social Applications by Jonathan LeBlanc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enum Data Types

With the enum data type, a developer can include a number of user-specified values within a single UserPref element. You can think of this type as an HTML drop-down list that allows the user to select a value from several different choices.

For example, let’s say we’re building a movie-rating widget and want to allow users to store movie ratings from 1–5 (with 0 meaning the user did not rate the movie). We could increase the base UserPref node with our additional EnumValue nodes:

<UserPref name="rating" display_name="Rating" datatype="enum" default_value="0">
   <EnumValue value="1" display_value="Worst Movie Ever"/>
   <EnumValue value="2" display_value="I just wasted 2 hours of my life"/>
   <EnumValue value="3" display_value="Meh"/>
   <EnumValue value="4" display_value="That was pretty entertaining"/>
   <EnumValue value="5" display_value="Epic"/>
</UserPref>

We specify enum as our data type, and within the UserPref node we define the EnumValue nodes for each rating value the user can choose from. Each node has a display value that the user sees (e.g., “Epic”) and a value that the developer uses to denote the chosen option (e.g., “5”).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required