mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
fix(web): handle string boolean values in schedule-picker widget (#227)
* fix(web): handle string boolean values in schedule-picker widget The normalizeSchedule function used strict equality (===) to check the enabled field, which would fail if the config value was a string "true" instead of boolean true. This could cause the checkbox to always appear unchecked even when the setting was enabled. Added coerceToBoolean helper that properly handles: - Boolean true/false (returns as-is) - String "true", "1", "on" (case-insensitive) → true - String "false" or other values → false Applied to both main schedule enabled and per-day enabled fields. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: trim whitespace in coerceToBoolean string handling --------- Co-authored-by: Chuck <chuck@example.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -99,6 +99,21 @@
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce a value to boolean, handling string 'true'/'false' values
|
||||
* that may come from config files or form submissions.
|
||||
*/
|
||||
function coerceToBoolean(value) {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
const trimmed = value.trim().toLowerCase();
|
||||
return trimmed === 'true' || trimmed === '1' || trimmed === 'on';
|
||||
}
|
||||
return Boolean(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge user value with defaults
|
||||
*/
|
||||
@@ -109,7 +124,7 @@
|
||||
}
|
||||
|
||||
const schedule = {
|
||||
enabled: value.enabled === true,
|
||||
enabled: coerceToBoolean(value.enabled),
|
||||
mode: value.mode === 'per_day' ? 'per_day' : 'global',
|
||||
start_time: value.start_time || defaults.start_time,
|
||||
end_time: value.end_time || defaults.end_time,
|
||||
@@ -119,8 +134,10 @@
|
||||
// Merge days
|
||||
DAYS.forEach(day => {
|
||||
const dayConfig = (value.days && value.days[day]) || defaults.days[day];
|
||||
// Use coerceToBoolean but default to true if enabled is undefined
|
||||
const dayEnabled = dayConfig.enabled === undefined ? true : coerceToBoolean(dayConfig.enabled);
|
||||
schedule.days[day] = {
|
||||
enabled: dayConfig.enabled !== false,
|
||||
enabled: dayEnabled,
|
||||
start_time: dayConfig.start_time || defaults.days[day].start_time,
|
||||
end_time: dayConfig.end_time || defaults.days[day].end_time
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user