diff --git a/awx/ui/src/components/Schedule/shared/ScheduleForm.js b/awx/ui/src/components/Schedule/shared/ScheduleForm.js index a41bb9195f..143cb3b445 100644 --- a/awx/ui/src/components/Schedule/shared/ScheduleForm.js +++ b/awx/ui/src/components/Schedule/shared/ScheduleForm.js @@ -412,24 +412,8 @@ function ScheduleForm({ } }); - if (values.exceptionFrequency.length > 0) { - let rangeToCheck = 1; - values.frequency.forEach((freq) => { - if (NUM_DAYS_PER_FREQUENCY[freq] > rangeToCheck) { - rangeToCheck = NUM_DAYS_PER_FREQUENCY[freq]; - } - }); - const ruleSet = buildRuleSet(values, true); - const startDate = DateTime.fromISO(values.startDate); - const endDate = startDate.plus({ days: rangeToCheck }); - const instances = ruleSet.between( - startDate.toJSDate(), - endDate.toJSDate(), - true - ); - if (instances.length === 0) { - errors.exceptionFrequency = t`This schedule has no occurrences due to the selected exceptions.`; - } + if (values.exceptionFrequency.length > 0 && !scheduleHasInstances(values)) { + errors.exceptionFrequency = t`This schedule has no occurrences due to the selected exceptions.`; } return errors; @@ -539,3 +523,24 @@ ScheduleForm.defaultProps = { }; export default ScheduleForm; + +function scheduleHasInstances(values) { + let rangeToCheck = 1; + values.frequency.forEach((freq) => { + if (NUM_DAYS_PER_FREQUENCY[freq] > rangeToCheck) { + rangeToCheck = NUM_DAYS_PER_FREQUENCY[freq]; + } + }); + + const ruleSet = buildRuleSet(values, true); + const startDate = DateTime.fromISO(values.startDate); + const endDate = startDate.plus({ days: rangeToCheck }); + const instances = ruleSet.between( + startDate.toJSDate(), + endDate.toJSDate(), + true, + (date, i) => i === 0 + ); + + return instances.length > 0; +} diff --git a/awx/ui/src/components/Schedule/shared/ScheduleFormFields.js b/awx/ui/src/components/Schedule/shared/ScheduleFormFields.js index 887e6f7535..6bf6e65a85 100644 --- a/awx/ui/src/components/Schedule/shared/ScheduleFormFields.js +++ b/awx/ui/src/components/Schedule/shared/ScheduleFormFields.js @@ -171,7 +171,7 @@ export default function ScheduleFormFields({ >