Could I create a field, the value in database in number, but there is a mapping for text to show on screen? For example, I have a field to record the "status", the possible value is "active", "closed", "duplicated", "fixed". I can use a text field, but if I use text field, when I want to change the value (i.e change "fixed" to "resolved"), I need to modify the database manually.

Therefore, is it possible to create a number field, the value is 1,2,3,4,5, ... and I can configure a mapping for 1=active, 2=closed, 3=duplicated, 4=fixed, .....

Comments

markus_petrux’s picture

You can use optionwidgets with a number field (that's a number field with radios/checkboxes or select lists widgets). And in the allowed values list you build the mapping like this:

1|active
2|closed
3|duplicated
4|fixed

The values on left of the character | is the value stored in database, and the value on the right is the label used to display the value in the form widget and when the node is displayed.

At any time you can change the labels, or even add more values:

1|active
2|closed
3|duplicated
4|resolved
5|won't fix

You can use optionwidgets with fields of type text or number, depending on the value you really need to store in the database. The label is always controlled by the right side value on the allowed values list.

dennys’s picture

Status: Active » Closed (fixed)

Thanks, it works. CCK is great !!