0

I have a custom page type with two fields, StateName and StateCode. I would like it so that when a value is selected in either of these fields, the other field’s value changes to match.

So for example, if I select “Alabama” in the StateName field, the value of the StateCode field would automatically change to “AL.” Or if I select “CO” in the StateCode field, the StateName field would automatically change to “Colorado,” etc. Is this possible?

State Fields

(I have to keep these as two separate fields, because I need to display either the state name or the state code on the front-end depending on context. Therefore, I can’t use a single field with options like AL;Alabama because then the field only returns the value AL and I have no way of getting the display name Alabama).

I know Kentico has options for setting “dependent” fields, but that only appears to determine visibility – e.g. only display Field B if I select a particular value in Field A. I can’t find a way to actually change the selected value in one field based on the selected value in another field.

1 Answer 1

0

Two control solution seems some kind of an overkill here. You can use StateInfoProvider to get what you want.

StateInfo state = StateInfoProvider.GetStateInfo("Alabama")

The other way would be to use a simple drop down control and use query like that :

select stateCode + '|'+ StateDisplayName, StateDisplayName  from cms_State

to get get code and display name as value separated by |

2
  • You mean I can just have one field with the state names and then use StateInfoProvider to get the state code from that? (One possible complication is that one of the items in the list is not actually a state, but just a custom value – what would happen in that case?)
    – daGUY
    Commented Feb 6, 2020 at 14:55
  • Ok . To make things simple go with the second option when your value will contain a code and a display name (separated by some character). All api will produce a sql query at the backend StateInfoProvider.Get ... will make a SQL query. You are better off parsing the value, if you want both code and name at the same time. Commented Feb 6, 2020 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.