From 004bf67f54a3eeed4973b5be65d55f2b87ee49f1 Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 16 Dec 2025 12:46:36 +0100 Subject: [PATCH] fix: add missing validate_amount_format function - Function was referenced but not defined - Cleans invalid characters from amount input - Provides better UX by sanitizing input --- .../live/membership_fee_type_live/form.ex | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/mv_web/live/membership_fee_type_live/form.ex b/lib/mv_web/live/membership_fee_type_live/form.ex index 5523bc4..d9fe084 100644 --- a/lib/mv_web/live/membership_fee_type_live/form.ex +++ b/lib/mv_web/live/membership_fee_type_live/form.ex @@ -328,6 +328,34 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do assign(socket, form: to_form(form)) end + # Validates amount format and cleans invalid characters + defp validate_amount_format(params) do + case Map.get(params, "amount") do + nil -> params + "" -> params + amount_str when is_binary(amount_str) -> + # Check if it's a valid number format + case Decimal.parse(amount_str) do + {_decimal, ""} -> + # Valid decimal + params + + {_decimal, _rest} -> + # Has trailing characters - invalid, but let Ash handle validation + params + + :error -> + # Not a valid number - try to clean it up + # Remove non-numeric characters except decimal point + cleaned = String.replace(amount_str, ~r/[^\d.]/, "") + Map.put(params, "amount", cleaned) + end + + _ -> + params + end + end + # Helper to extract existing form values to preserve them when only one field changes defp get_existing_form_values(form) do # Extract values directly from form fields to get current state