From 37c2a8a5de74af1bc5671566877763ba1fb7cb40 Mon Sep 17 00:00:00 2001 From: Dossy Shiobara Date: Mon, 20 Mar 2023 22:16:01 -0400 Subject: fix: settings input validation and error handling (#609) Co-authored-by: Ven --- src/components/PluginSettings/components/SettingNumericComponent.tsx | 5 ++++- src/components/PluginSettings/components/SettingSelectComponent.tsx | 1 + src/components/PluginSettings/components/SettingTextComponent.tsx | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/PluginSettings/components/SettingNumericComponent.tsx b/src/components/PluginSettings/components/SettingNumericComponent.tsx index 12e8e36..446d250 100644 --- a/src/components/PluginSettings/components/SettingNumericComponent.tsx +++ b/src/components/PluginSettings/components/SettingNumericComponent.tsx @@ -38,9 +38,12 @@ export function SettingNumericComponent({ option, pluginSettings, definedSetting function handleChange(newValue) { const isValid = option.isValid?.call(definedSettings, newValue) ?? true; + + setError(null); if (typeof isValid === "string") setError(isValid); else if (!isValid) setError("Invalid input provided."); - else if (option.type === OptionType.NUMBER && BigInt(newValue) >= MAX_SAFE_NUMBER) { + + if (option.type === OptionType.NUMBER && BigInt(newValue) >= MAX_SAFE_NUMBER) { setState(`${Number.MAX_SAFE_INTEGER}`); onChange(serialize(newValue)); } else { diff --git a/src/components/PluginSettings/components/SettingSelectComponent.tsx b/src/components/PluginSettings/components/SettingSelectComponent.tsx index 164a29a..97c1707 100644 --- a/src/components/PluginSettings/components/SettingSelectComponent.tsx +++ b/src/components/PluginSettings/components/SettingSelectComponent.tsx @@ -36,6 +36,7 @@ export function SettingSelectComponent({ option, pluginSettings, definedSettings if (typeof isValid === "string") setError(isValid); else if (!isValid) setError("Invalid input provided."); else { + setError(null); setState(newValue); onChange(newValue); } diff --git a/src/components/PluginSettings/components/SettingTextComponent.tsx b/src/components/PluginSettings/components/SettingTextComponent.tsx index 599593f..9eccb10 100644 --- a/src/components/PluginSettings/components/SettingTextComponent.tsx +++ b/src/components/PluginSettings/components/SettingTextComponent.tsx @@ -34,6 +34,7 @@ export function SettingTextComponent({ option, pluginSettings, definedSettings, if (typeof isValid === "string") setError(isValid); else if (!isValid) setError("Invalid input provided."); else { + setError(null); setState(newValue); onChange(newValue); } -- cgit