First excuse me because I’m not very comfortable with English.
I got EctoEnum an extension to Ecto from here; https://github.com/gjaldon/ecto_enum.
Then I followed the readme instructions and now I have a StatusEnum type (registered: 0, active: 1, inactive: 2, archived: 3).
In my migrations file for a users table I add a column status and sert its type to integer since that’s the type expected by EctoEnum in database. (Though I would like to use string instead, but that’s okay)
Then in User model I set status field to StatusEnum type.
Until now all’s going well as expected. When I use a text input in new user form for status field, only expected entries are accepted (registered, active, inactive, archived).
But the problem is when I want to use form select instead of text input. The StatusEnum type have a method named enum_map which returns this list: [registered: 0, active: 1, inactive: 2, archived: 3].
So when providing this list to the form select, I got an invalid type error from the form validatior, on submit. I understand that’s a normal thing, since User model changeset is expecting a string entry for the status field instead of an integer as the list provided to the form select will be returning.
A solution could be providind by hand the suitable List to the form select, such as [“registered”, “active”, “inactive”, “archived”]. But If the StatusEnum type changes in future, I wiil have to update also my form template. I think that’s not very convenient.
Another solution that came to my mind will be setting User model status field type to integer. But then I won’t take advantage from the EctoEnum validators through StatusEnum.
I think the matter comes mainly from the fact I’m a newcomer to elixir, but please can you help me to find the best and simple way to handle this ?
Should I writte my own method, in addition to EctoEnum extension, to retrieve the form select options ?
Or should I drop this library and then what’s to do ?
Also I would like to be able to use french accented characters in the form select options. I’m mentionning that because I noticed that such characters can’t be used as elixir atoms.
I hope that my topic is more or less comprehensive. Thank you ^^