https://avo.cool logo
Hey guys, how are you? A quick question. The...
# fields
m
Hey guys, how are you? A quick question. The [status field](https://docs.avohq.io/3.0/fields/status.html) works like a text input when creating a new record from AVO. Is it possible to change it to behave like a select with the Model.statuses options? Because I really like how it looks when it's defined as a status in the index view with those well-defined labels.
m
Thread automatically created by Bruno Costanzo in #fields
l
Idk off the top of my head. I would guess you tried it and it didn’t work?
But you still need to tell it the different states (failed, loading, etc)
Maybe Model.statuses.map(:&to_s)
m
field :status, as: :select, enum: Model.statuses Works fine. field :status, as: :status, enum: Model.statuses does not, But it shows the field with better designs.
This is working now: field :status, as: :status, success_when: [ :active ], hide_on: [ :new, :edit ] field :status, as: :select, enum: VirtualMachine.statuses, only_on: [ :new, :edit ] So it uses the select only on the new and edit actions.
l
The status field does not have an enumerate option AFAIK
also, you have to declare each one per type of status
Your solution is the proper one
GJ
m
Thank you Adrian!
l
Hi @magnificent-jackal-1244 👋 Nice to see you here! The solution that you end up with is a good one If you want this behavior of having a select for status all over your app maybe is worth to eject the edit component for the status field and adapt it to be a select To eject the edit component for the status field you can run
rails g avo:eject --field-components status --view edit
Then you can modify its behavior into a select, and use
meta
arg on the field to pass any custom arguments from the resource https://cdn.discordapp.com/attachments/1420423655069978675/1422887723626270782/image.png?ex=68de4ef5&is=68dcfd75&hm=558a0feacbe8f81ff51dd9e1651a70f4bd3fc518bbbb0bd0dc5832fd8ba5c5f6&
m
woww @loud-jewelry-99127 really nice! thank you
l
Anytime!