|
7 | 7 | </div> |
8 | 8 |
|
9 | 9 | <!-- 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> |
11 | 11 | <!-- Tab Navigation --> |
12 | 12 | <div class="sticky top-0 z-10 overflow-x-auto settings-tabs-scroll"> |
13 | 13 | <nav class="settings-tabs"> |
@@ -2198,6 +2198,35 @@ async function saveSettings() { |
2198 | 2198 | return |
2199 | 2199 | } |
2200 | 2200 |
|
| 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 | +
|
2201 | 2230 | const payload: UpdateSettingsRequest = { |
2202 | 2231 | registration_enabled: form.registration_enabled, |
2203 | 2232 | email_verify_enabled: form.email_verify_enabled, |
|
0 commit comments