refactor: remove manual amount validation, use Ash default validation

- Remove validate_amount_format function - Ash handles Decimal validation automatically
- Remove oninput and pattern attributes - not needed with Ash validation
- Simplify validate handler - let AshPhoenix.Form.validate do its job
- Follows Ash best practices for form validation
This commit is contained in:
Moritz 2025-12-16 12:51:15 +01:00
parent 004bf67f54
commit 0ab6a75377
Signed by: moritz
GPG key ID: 1020A035E5DD0824

View file

@ -46,9 +46,6 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
label={gettext("Amount")}
step="0.01"
min="0"
pattern="[0-9]+(\.[0-9]{1,2})?"
phx-debounce="blur"
oninput="this.setCustomValidity(''); if (!this.validity.valid) { this.setCustomValidity('Please enter a valid number'); }"
required
/>
@ -210,9 +207,6 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
@impl true
def handle_event("validate", %{"membership_fee_type" => params}, socket) do
# Validate amount format if present
params = validate_amount_format(params)
# Merge with existing form values to preserve unchanged fields
# Extract values directly from form fields to get current state
existing_values = get_existing_form_values(socket.assigns.form)
@ -231,6 +225,7 @@ defmodule MvWeb.MembershipFeeTypeLive.Form do
merged_params
end
# Let Ash handle validation automatically - it will validate Decimal format
validated_form = AshPhoenix.Form.validate(socket.assigns.form, merged_params)
# Check if amount changed on edit