From 4b540faec42b8820527746cda5b8a96939908be5 Mon Sep 17 00:00:00 2001 From: StarFleetCPTN Date: Fri, 11 Apr 2025 12:03:16 -0700 Subject: [PATCH] feat: Implement form validation for job creation and editing - Added a comprehensive validation script for the job form to ensure all fields are correctly filled before submission. - Introduced error handling for job name, schedule, and configuration selection, displaying relevant messages to users. - Enhanced the user interface with error containers that dynamically show validation messages. - Updated the job form layout to include validation attributes and improve accessibility. --- components/job_form.templ | 526 ++++++++++++++++++++++++++++++++++++- internal/logging/logger.go | 8 +- 2 files changed, 523 insertions(+), 11 deletions(-) diff --git a/components/job_form.templ b/components/job_form.templ index c6df338..4d2b8cd 100644 --- a/components/job_form.templ +++ b/components/job_form.templ @@ -295,9 +295,11 @@ templ scheduleBuilderScript() { const updateCronExpression = () => { const scheduleType = scheduleTypeSelect.value; let cronExpression = ''; + let hasError = false; switch (scheduleType) { case 'interval': + const intervalValueEl = document.getElementById(`${prefixId}interval-value`); const intervalValue = document.getElementById(`${prefixId}interval-value`).value || '15'; const intervalUnit = document.getElementById(`${prefixId}interval-unit`).value || 'minutes'; @@ -457,13 +459,25 @@ templ scheduleBuilderScript() { if (scheduleTypeSelect.value !== 'custom') { updateCronExpression(); } + + // Also validate the schedule builder when type changes + if (window.validateScheduleFields) { + window.validateScheduleFields(prefixId); + } }); // Add listeners to all schedule builder inputs const attachListeners = (selector) => { const elements = document.querySelectorAll(selector); elements.forEach(el => { - el.addEventListener('change', updateCronExpression); + el.addEventListener('change', () => { + updateCronExpression(); + + // Also validate this field when value changes + if (window.validateScheduleFields) { + window.validateScheduleFields(prefixId); + } + }); el.addEventListener('input', updateCronExpression); }); }; @@ -482,10 +496,480 @@ templ scheduleBuilderScript() { } +templ formValidationScript() { + +} + templ JobForm(ctx context.Context, data JobFormData) { @LayoutWithContext(getJobFormTitle(data.IsNew), ctx) { @configSearchScript() @scheduleBuilderScript() + @formValidationScript()
@@ -520,6 +1004,16 @@ templ JobForm(ctx context.Context, data JobFormData) { if data.IsNew {
+ + +

@@ -541,6 +1035,7 @@ templ JobForm(ctx context.Context, data JobFormData) { id="name" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full ps-10 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Daily Production Backup" + maxlength="100" />

@@ -552,7 +1047,7 @@ templ JobForm(ctx context.Context, data JobFormData) {

@@ -914,7 +1423,7 @@ templ JobForm(ctx context.Context, data JobFormData) {