mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Show flash error if preferred amount isn't valid
This commit is contained in:
@@ -7,6 +7,7 @@ module Spree
|
||||
before_action :load_data
|
||||
before_action :validate_payment_method_provider, only: [:create]
|
||||
before_action :load_hubs, only: [:new, :edit, :update]
|
||||
before_action :validate_calculator_preferred_amount, only: [:update]
|
||||
|
||||
respond_to :html
|
||||
|
||||
@@ -173,6 +174,16 @@ module Spree
|
||||
params_for_update
|
||||
end
|
||||
end
|
||||
|
||||
def validate_calculator_preferred_amount
|
||||
preferred_amount = params.dig(:payment_method_check, :calculator_attributes,
|
||||
:preferred_amount)
|
||||
return if preferred_amount.nil? || Float(preferred_amount,
|
||||
exception: false)
|
||||
|
||||
flash[:error] = I18n.t(:calculator_preferred_amount_error)
|
||||
redirect_to spree.edit_admin_payment_method_path(@payment_method)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user