Skip to content

Commit 43d2ef1

Browse files
author
Spencer Brower
committed
feat: Allow prompt to accept input.
1 parent 9fcb5c5 commit 43d2ef1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/htmx.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,7 +4177,7 @@ var htmx = (function() {
41774177
* @param {Element} elt
41784178
* @param {Event} event
41794179
* @param {HtmxAjaxEtc} [etc]
4180-
* @param {boolean} [confirmed]
4180+
* @param {string|false} [confirmed]
41814181
* @return {Promise<void>}
41824182
*/
41834183
function issueAjaxRequest(verb, path, elt, event, etc, confirmed) {
@@ -4232,7 +4232,7 @@ var htmx = (function() {
42324232
// allow event-based confirmation w/ a callback
42334233
if (confirmed === undefined) {
42344234
const issueRequest = function(skipConfirmation) {
4235-
return issueAjaxRequest(verb, path, elt, event, etc, !!skipConfirmation)
4235+
return issueAjaxRequest(verb, path, elt, event, etc, skipConfirmation)
42364236
}
42374237
const confirmDetails = { target, elt, path, verb, triggeringEvent: event, etc, issueRequest, question: confirmQuestion }
42384238
if (triggerEvent(elt, 'htmx:confirm', confirmDetails) === false) {
@@ -4325,13 +4325,17 @@ var htmx = (function() {
43254325
}
43264326
const promptQuestion = getClosestAttributeValue(elt, 'hx-prompt')
43274327
if (promptQuestion) {
4328-
var promptResponse = prompt(promptQuestion)
4329-
// prompt returns null if cancelled and empty string if accepted with no entry
4330-
if (promptResponse === null ||
4331-
!triggerEvent(elt, 'htmx:prompt', { prompt: promptResponse, target })) {
4332-
maybeCall(resolve)
4333-
endRequestLock()
4334-
return promise
4328+
if (confirmed) {
4329+
var promptResponse = confirmed
4330+
} else {
4331+
var promptResponse = prompt(promptQuestion)
4332+
// prompt returns null if cancelled and empty string if accepted with no entry
4333+
if (promptResponse === null ||
4334+
!triggerEvent(elt, 'htmx:prompt', { prompt: promptResponse, target })) {
4335+
maybeCall(resolve)
4336+
endRequestLock()
4337+
return promise
4338+
}
43354339
}
43364340
}
43374341

0 commit comments

Comments
 (0)