Skip to content

Commit 1add030

Browse files
authored
bug fix: add input validation to showInputBoxWithButtons (#474)
fixes #468
1 parent 4ff9df2 commit 1add030

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/common/window.apis.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,17 @@ export async function showInputBoxWithButtons(
255255
inputBox.hide();
256256
}
257257
}),
258-
inputBox.onDidAccept(() => {
258+
inputBox.onDidAccept(async () => {
259259
if (!deferred.completed) {
260+
let isValid = true;
261+
if (options?.validateInput) {
262+
const validation = await options.validateInput(inputBox.value);
263+
isValid = validation === null || validation === undefined;
264+
if (!isValid) {
265+
inputBox.validationMessage = typeof validation === 'string' ? validation : 'Invalid input';
266+
return; // Do not resolve, keep the input box open
267+
}
268+
}
260269
deferred.resolve(inputBox.value);
261270
inputBox.hide();
262271
}

0 commit comments

Comments
 (0)