Skip to content

Commit 73eb731

Browse files
Eilen6316claude
andcommitted
fix: prevent silent save failure in admin settings form
The settings form contains multiple <input type="url"> fields that lack a name attribute. When a field value fails browser URL validation, the browser silently blocks form submission without showing an error — no network request is made, and the user sees no feedback. Root cause: HTML5 form validation requires a focusable element with a name attribute to surface errors. Without it, validation fails silently. Fix: - Add novalidate to the <form> to disable browser-native URL validation - Add an isValidHttpUrl() helper in saveSettings() to replicate the same checks the backend performs - Optional URL fields (frontend_url, doc_url): auto-clear invalid values instead of blocking the save, matching backend behaviour (these fields accept empty string without error) - purchase_subscription_url: block save with a clear error message when enabled + invalid; auto-clear when disabled to prevent the backend 400 "Purchase Subscription URL must be an absolute http(s) URL" error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a225a24 commit 73eb731

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

frontend/src/views/admin/SettingsView.vue

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88

99
<!-- Settings Form -->
10-
<form v-else @submit.prevent="saveSettings" class="space-y-6">
10+
<form v-else @submit.prevent="saveSettings" class="space-y-6" novalidate>
1111
<!-- Tab Navigation -->
1212
<div class="sticky top-0 z-10 overflow-x-auto settings-tabs-scroll">
1313
<nav class="settings-tabs">
@@ -2198,6 +2198,35 @@ async function saveSettings() {
21982198
return
21992199
}
22002200
2201+
// Validate URL fields — novalidate disables browser-native checks, so we validate here
2202+
const isValidHttpUrl = (url: string): boolean => {
2203+
if (!url) return true
2204+
try {
2205+
const u = new URL(url)
2206+
return u.protocol === 'http:' || u.protocol === 'https:'
2207+
} catch {
2208+
return false
2209+
}
2210+
}
2211+
// Optional URL fields: auto-clear invalid values so they don't cause backend 400 errors
2212+
if (!isValidHttpUrl(form.frontend_url)) form.frontend_url = ''
2213+
if (!isValidHttpUrl(form.doc_url)) form.doc_url = ''
2214+
// Purchase URL: required when enabled; auto-clear when disabled to avoid backend rejection
2215+
if (form.purchase_subscription_enabled) {
2216+
if (!form.purchase_subscription_url) {
2217+
appStore.showError(t('admin.settings.purchase.url') + ': URL is required when purchase is enabled')
2218+
saving.value = false
2219+
return
2220+
}
2221+
if (!isValidHttpUrl(form.purchase_subscription_url)) {
2222+
appStore.showError(t('admin.settings.purchase.url') + ': must be an absolute http(s) URL (e.g. https://example.com)')
2223+
saving.value = false
2224+
return
2225+
}
2226+
} else if (!isValidHttpUrl(form.purchase_subscription_url)) {
2227+
form.purchase_subscription_url = ''
2228+
}
2229+
22012230
const payload: UpdateSettingsRequest = {
22022231
registration_enabled: form.registration_enabled,
22032232
email_verify_enabled: form.email_verify_enabled,

0 commit comments

Comments
 (0)