From 899c7c8a8867571c7b6668719de8f3826ceaf794 Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Tue, 15 Jul 2025 15:42:14 -0400 Subject: [PATCH] feat: Allow prompt to accept input. --- src/htmx.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/htmx.js b/src/htmx.js index 424da472c..799924693 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -4177,7 +4177,7 @@ var htmx = (function() { * @param {Element} elt * @param {Event} event * @param {HtmxAjaxEtc} [etc] - * @param {boolean} [confirmed] + * @param {string|boolean} [confirmed] * @return {Promise} */ function issueAjaxRequest(verb, path, elt, event, etc, confirmed) { @@ -4232,7 +4232,11 @@ var htmx = (function() { // allow event-based confirmation w/ a callback if (confirmed === undefined) { const issueRequest = function(skipConfirmation) { - return issueAjaxRequest(verb, path, elt, event, etc, !!skipConfirmation) + // convert non-empty strings to boolean + const skip = (typeof skipConfirmation === 'string' && skipConfirmation.length > 0) + ? skipConfirmation + : !!skipConfirmation; + return issueAjaxRequest(verb, path, elt, event, etc, skip) } const confirmDetails = { target, elt, path, verb, triggeringEvent: event, etc, issueRequest, question: confirmQuestion } if (triggerEvent(elt, 'htmx:confirm', confirmDetails) === false) { @@ -4325,13 +4329,17 @@ var htmx = (function() { } const promptQuestion = getClosestAttributeValue(elt, 'hx-prompt') if (promptQuestion) { - var promptResponse = prompt(promptQuestion) - // prompt returns null if cancelled and empty string if accepted with no entry - if (promptResponse === null || - !triggerEvent(elt, 'htmx:prompt', { prompt: promptResponse, target })) { - maybeCall(resolve) - endRequestLock() - return promise + if (confirmed) { + var promptResponse = confirmed + } else { + var promptResponse = prompt(promptQuestion) + // prompt returns null if cancelled and empty string if accepted with no entry + if (promptResponse === null || + !triggerEvent(elt, 'htmx:prompt', { prompt: promptResponse, target })) { + maybeCall(resolve) + endRequestLock() + return promise + } } }