Below is a sample of a rule (in Rules export format) that you can use as a prototype to answer your question by using the Rules module:
{ "rules_set_field_value_based_on_value_of_selection_list_field" : {
"LABEL" : "Set field value based on value of selection list field",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_conditional" ],
"ON" : { "node_presave" : [] },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } },
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_free_format_text" } }
],
"DO" : [
{ "SWITCH" : {
"USING" : { "data" : [ "node:field-optionlist" ] },
"DO" : [
{ "CASE" : {
"USING" : { "value" : "B" },
"DO" : [
{ "data_set" : { "data" : [ "node:field-free-format-text" ], "value" : "B.A.S.I.C." } }
]
}
},
{ "CASE" : {
"USING" : { "value" : "A" },
"DO" : [
{ "data_set" : { "data" : [ "node:field-free-format-text" ], "value" : "A.D.V.A.N.C.E.D." } }
]
}
}
]
}
}
]
}
}
Some more details to further explain the above above sample:
- The Rules event I'm using is "before saving content".
In my case I have these fields:
- a selection list field with machine name
field_optionlist
.
- a text field with machine name
field_free_format_text
.
The selection list field actually has 3 possible values, like so:
- A (=Advanced).
- B (=Basic).
- C (=Custom).
As a sample, I decided to set the values of the text field like so:
- B.A.S.I.C. if "The selection list field's value is
Basic
".
- A.D.V.A.N.C.E.D. if "The selection list field's value is
Advanced
".
- Leave it unchanged if "The selection list field's value is
Custom
"
Part of the "clue" to make this rule work is the condition Entity has field
. That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')". I wouldn't be surprised if that is what you are missing in the rules conditions you tried so far ...
For a video tutorial that illustrates the importance of this Entity has field
condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in that video.
However, to make the above work, and to be able to get this to work with only 1 rule (instead of writing 2 rules, ie one for "Basic", and one for "Advanced"), I also used the "Conditional Rules module. That way you could expand the above prototype to say dozens of different possible values. For a sample using the Rules Conditional module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?".
Note: the Field Permissions module should help you to make such text field read only.