I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lookup table example is U. S. States. You might have something like this:
State Id State Name State Abbrev 1 Alabama AL 2 Alaska AK 3 Arizona AZ
etc. etc.
Now in other tables that need to reference the state I’d use an integer field which is a foreign key to my state table:
Street Address City StateId Zip
123 Any Street AnyTown 1 11111
456 Any Avenue OtherTown 2 22222
etc.
Of course when I want data entry I don’t want to display the Id; I want to display the name in order to make it easy for my end user to select the right value. Is there a core component or some simple way to roll my own control such that it creates the proper tag for me? Something like (contiuning with the state example):
Although note that this will return the subdivision (state for the US) short code. Ie al for Alabama, not 1. You could use the :mapper option to generate integers if thats a firm requirement.
Using localize_web means you can easily select subdivisions for other territories (countries), localize the content to a given language and sort the subdivisions appropriately (different locales sort differently). All of that comes “for free”.
If you are looking for an alternative, Corex Select component let you use either your own list or Localize values instead. Works in Controller and Live View
I used a similar approach for the language switch, Localize is great for getting each language names in each in its own language.
Thanks for that but the state list was solely intended as an example of the issue I’m trying to solve. Still I might be able to use that stuff to solve the issue I am trying to solve so I greatly appreciate the pointer.