| @@ -208,14 +208,45 @@ | ||
| 208 | 208 | }); |
| 209 | 209 | |
| 210 | 210 | const select = document.getElementById("basalam-sync-type"); |
| 211 | 211 | if (select) { |
| 212 | + const customFields = document.getElementById("Basalam-custom-fields"); | |
| 213 | + const settingsForm = select.closest("form"); | |
| 214 | + const validationMessage = | |
| 215 | + "در حالت سفارشی باید حداقل یک فیلد را برای بروزرسانی انتخاب کنید."; | |
| 216 | + | |
| 212 | 217 | const toggleFields = (val) => { |
| 213 | - document.getElementById("Basalam-custom-fields").style.display = | |
| 214 | - val === "custom" ? "block" : "none"; | |
| 218 | + if (customFields) { | |
| 219 | + customFields.style.display = val === "custom" ? "block" : "none"; | |
| 220 | + } | |
| 215 | 221 | }; |
| 222 | + | |
| 223 | + const hasSelectedCustomField = () => | |
| 224 | + customFields && | |
| 225 | + Array.from( | |
| 226 | + customFields.querySelectorAll('input[type="checkbox"]') | |
| 227 | + ).some((checkbox) => checkbox.checked); | |
| 228 | + | |
| 216 | 229 | toggleFields(select.value); |
| 217 | 230 | select.addEventListener("change", (e) => toggleFields(e.target.value)); |
| 231 | + | |
| 232 | + if (settingsForm) { | |
| 233 | + settingsForm.addEventListener("submit", (event) => { | |
| 234 | + if (select.value !== "custom" || hasSelectedCustomField()) return; | |
| 235 | + | |
| 236 | + event.preventDefault(); | |
| 237 | + event.stopImmediatePropagation(); | |
| 238 | + | |
| 239 | + if (window.BasalamToast) { | |
| 240 | + window.BasalamToast.error(validationMessage); | |
| 241 | + } | |
| 242 | + | |
| 243 | + if (customFields) { | |
| 244 | + customFields.scrollIntoView({ behavior: "smooth", block: "center" }); | |
| 245 | + customFields.querySelector('input[type="checkbox"]')?.focus(); | |
| 246 | + } | |
| 247 | + }, true); | |
| 248 | + } | |
| 218 | 249 | } |
| 219 | 250 | |
| 220 | 251 | // Tab functionality for settings modal |
| 221 | 252 | const initTabs = () => { |