miniature-optician-85831
11/23/2023, 10:22 PMlemon-wall-20836
11/24/2023, 10:25 AMloud-jewelry-99127
11/24/2023, 1:12 PMloud-jewelry-99127
11/24/2023, 1:18 PMvalue method on your custom field?late-noon-56486
11/24/2023, 6:09 PMbash
bin/rails generate avo:field currency
Avo pro 2.44.0
create app/components/avo/fields/currency_field
create app/components/avo/fields/currency_field/edit_component.html.erb
create app/components/avo/fields/currency_field/edit_component.rb
create app/components/avo/fields/currency_field/index_component.html.erb
create app/components/avo/fields/currency_field/index_component.rb
create app/components/avo/fields/currency_field/show_component.html.erb
create app/components/avo/fields/currency_field/show_component.rb
create app/avo/fields/currency_field.rb
^ I am not changing anything in these files.
And then in client_resource.rb I am setting:
field :meal_budget_consumption_adjustment,
as: :currency,
name: "Budget spent on client?",
format_using: -> { "20.00" }
If go to the edit view, the field works but does not utilize the format_using block. If I set this to as: :text or as: :number then it utilizes format_using.late-noon-56486
11/24/2023, 6:11 PMcurrency_field.rb
ruby
class CurrencyField < Avo::Fields::BaseField
def initialize(name, **args, &block)
super(name, **args, &block)
end
end
edit_component.html.erb
<%= field_wrapper **field_wrapper_args do %>
<%= @form.text_field @field.id,
class: classes("w-full"),
placeholder: @field.placeholder,
disabled: disabled? %>
<% end %>late-noon-56486
11/24/2023, 6:20 PMformat_using works on the index and show pages but not on the edit page.late-noon-56486
11/24/2023, 6:24 PM@field.value like so:
edit_component.html.erb
<%= field_wrapper **field_wrapper_args do %>
<%= @form.text_field @field.id,
class: classes("w-full"),
placeholder: @field.placeholder,
disabled: disabled?,
value: @field.value %>
<% end %>loud-jewelry-99127
11/24/2023, 6:28 PMloud-jewelry-99127
11/24/2023, 6:30 PMlate-noon-56486
11/24/2023, 6:36 PMformat_using for each instance of the field. Where would be the ideal place to do that from?
I know I can specify a default value for format_using from the currency class in currency_field.rb but I'm not sure that would be considered best practice.loud-jewelry-99127
11/24/2023, 6:38 PMloud-jewelry-99127
11/24/2023, 6:39 PMloud-jewelry-99127
11/24/2023, 6:39 PMloud-jewelry-99127
11/24/2023, 6:39 PMlate-noon-56486
11/24/2023, 6:40 PMclass CurrencyField < Avo::Fields::BaseField
def initialize(name, **args, &block)
super(name, **args, &block)
@format_using = args[:format_using] || -> { "20.00" }
end
endloud-jewelry-99127
11/24/2023, 6:41 PMloud-jewelry-99127
11/24/2023, 6:41 PMformat_using:...loud-jewelry-99127
11/24/2023, 6:42 PMclass CurrencyField < Avo::Fields::BaseField
def initialize(name, **args, &block)
super(name, **args, &block)
@format_using = -> { "20.00" }
end
endlate-noon-56486
11/24/2023, 6:43 PMclass CurrencyField < Avo::Fields::BaseField
def initialize(name, **args, &block)
args[:format_using] ||= -> { "20.00" }
super(name, **args, &block)
end
end
?loud-jewelry-99127
11/24/2023, 6:43 PMloud-jewelry-99127
11/24/2023, 6:43 PMloud-jewelry-99127
11/24/2023, 6:43 PMlate-noon-56486
11/24/2023, 6:44 PMlate-noon-56486
11/24/2023, 6:44 PMclass CurrencyField < Avo::Fields::BaseField
def initialize(name, **args, &block)
super(name, **args, &block)
@format_using = args[:format_using] || -> { "20.00" }
end
end
but I will go with your suggestionloud-jewelry-99127
11/24/2023, 6:46 PM