As the title says: I’m looking to have form inputs in derived units (for instance, kilograms) for schema fields in base units (grams, for that example).
There will be many of these fields, as the application domain is simulation and control of physical systems. As a result, I’m looking for a way to do this without writing a lot of code for each field.
I can get halfway there with a custom
Ecto.Type that converts derived → base when
casting string → float to handle conversion on form submission, but it’s unclear how to handle the other half: converting base → derived to generate the HTML input.
One option for that part would be a custom input helper (to replace
text_input for these fields): can anybody think of a simpler / shorter approach?