Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
markus_petrux CreditAttribution: markus_petrux commentedYou 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:
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:
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.
Comment #2
dennys CreditAttribution: dennys commentedThanks, it works. CCK is great !!