|
92 | 92 | let scheduleName = ""; |
93 | 93 | let selectedEnvironment = ""; |
94 | 94 | let isError = false; |
| 95 | + let isErrors = { |
| 96 | + scheduleNameError: false, |
| 97 | + }; |
95 | 98 | let isUpdating = false; |
96 | 99 | let selectedTestData = "none"; |
97 | 100 |
|
|
511 | 514 | $: if (formattedDate) { |
512 | 515 | selectedDate = parseDateString(formattedDate); |
513 | 516 | } |
| 517 | +
|
| 518 | + const isValidScheduleName = (name: string) => { |
| 519 | + // Regex: 1–30 characters, allows letters, numbers, spaces, hyphens, and underscores |
| 520 | + const regex = /^[A-Za-z0-9 _-]{1,30}$/; |
| 521 | + return regex.test(name); |
| 522 | + }; |
| 523 | +
|
| 524 | + $: { |
| 525 | + if (scheduleName && scheduleName.trim()) { |
| 526 | + if (!isValidScheduleName(scheduleName.trim())) { |
| 527 | + isErrors.scheduleNameError = true; |
| 528 | + } else { |
| 529 | + isErrors.scheduleNameError = false; |
| 530 | + } |
| 531 | + } else { |
| 532 | + isErrors.scheduleNameError = false; |
| 533 | + } |
| 534 | + } |
514 | 535 | </script> |
515 | 536 |
|
516 | 537 | <div class="configurations-container"> |
|
542 | 563 | > |
543 | 564 | Schedule name is required |
544 | 565 | </p> |
| 566 | + {:else if isErrors.scheduleNameError} |
| 567 | + <p |
| 568 | + class="error-text text-ds-font-size-12 mt-1" |
| 569 | + style="color: var(--text-ds-danger-300);" |
| 570 | + > |
| 571 | + Schedule name must be 1-30 characters and can only contain letters, |
| 572 | + numbers, spaces, hyphens (-), and underscores (_). |
| 573 | + </p> |
545 | 574 | {/if} |
546 | 575 | </div> |
547 | 576 |
|
|
892 | 921 | disable={!isModified || |
893 | 922 | isSaved || |
894 | 923 | !scheduleName.trim() || |
| 924 | + isErrors.scheduleNameError || |
895 | 925 | (selectedCycle === "once" && (!formattedDate || !selectedTime)) || |
896 | 926 | (selectedCycle === "daily" && !selectedTime) || |
897 | 927 | (selectedCycle === "hourly" && !intervalHours) || |
|
0 commit comments