Base Enum without Default Value

December 12, 2007

Ever come across the need to capture enumerated data without the value filled in by default? We are going to look at two approaches and how they behave in different controls.

Enumerated data without default value here refers to fields with data type Base Enum that is not filled in when a new record is created. In other words, you would like the user to deliberately or implicitly select a value. The following figure shows a grid with new record. There are two columns both are of enumerated data type. The first column has no default value whereas the second has Normal as its default value.

Base Enum with and without default value

Approach #1: Blank Element Zero

One way to achieve this is to have the default element (value 0) configured with blank label. The following figure shows the setting for this approach. Element named “None” is the default element. Note that the label of this element is blank.

Base Enum with Blank Element Zero

This figure shows Base Enum FreightSlipType. You could see the corresponding field in Sales Order form. There is a field labeled Call tag type in the Delivery tab based on this Base Enum.

Approach #2: No Element Zero

The other way this is achieved is have no element with the value 0 in the Base Enum. The default value for an enumeration is zero. This will have the default value refers to none of the members of the enumeration.

The following figure shows a Base Enum with member elements starting from value 1. This Base Enum is created to illustrate this approach.

Base Enum with No Element Zero

Approach #1 vs Approach #2

I have created a form with the two methods of achieving no default value and a field with default value to show how they behave in different controls. The following figure shows the three types of Base Enum in three type of controls; combo box, radio button and list box.

Base Enum approach Comparison

In combo boxes, you see that both approaches started without a value. The drop down list for approach #1 (Call tag type) contains an empty line. This does not happen to the drop down list of approach #2 (No default). This means approach #1 enables the user to revert the value to empty but not the product of approach #2.

When the Base Enums are shown with radio button and list box, you will get an empty radio button and empty list entry respectively. Naturally, this does not affect radio button and list box based on approach #1.

Conclusion

Both approaches have their pros and cons. There are conditions where one is more suitable than the other.

Having blank element 0 produces a field that requires the user to choose a value and can be reverted to blank. This approach looks fine on a combo box but does not look good on radio button and list box. It is suitable for cases where it is optional.

Having no element 0 on the other hand produces a field that forces the user to pick a value. Once picked, the value cannot be reverted to blank. It can only be changed to some other value in the enumeration. This approach looks fine in all controls. It works very well to enforce mandatory field.

2 responses :

Amal said... (May 14, 2009 at 8:16 PM)

I'm wondering how to change the default value once a boatload of data has been entered? We have a bunch of part numbers in our production system and now we want to change the default value for one of the enums. I have tried changing the element number, but it appears that the data is stored based on element number and not name.

Unknown said... (December 29, 2014 at 11:09 AM)

Hi Really this Post makes me clear how to set default value for combo box as blank.But still need clarification on below scenario:

I am having Base Enum called Gender and contains elements Male and Female.And Now I am setting these Enum values to a combo box. Whenever i open the form the combo box contains Male as default value. But I want to have default value of combo box as blank.Is there any way to change this?

Note: I should not change the index positions of elements and also not to add any new element.

Can you please tell me how can this above scenario achieved?