fix: settings input validation and error handling (#609)
Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
parent
265547213c
commit
37c2a8a5de
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user