Skip to content

Custom hx-prompt dialogs. #3376

@sbrow

Description

@sbrow

While I've had great success creating custom hx-confirm dialogs, the same can not be said for hx-prompt. I'd like to prompt the user for their password before deleting their account, but prompt() shows the password.

It seems that, (unlike hx-request) the handler for hx-prompt is hard-coded to call prompt(), you can't pre-fill the data.

Is there a way this could be avoided such that hx-confirm and hx-prompt function in the same way?

hx-prompt

htmx/src/htmx.js

Lines 4383 to 4393 in 03c3af7

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
}
}

hx-confirm

htmx/src/htmx.js

Lines 4231 to 4240 in 03c3af7

/**
* @param {HttpVerb} verb
* @param {string} path
* @param {Element} elt
* @param {Event} event
* @param {HtmxAjaxEtc} [etc]
* @param {boolean} [confirmed]
* @return {Promise<void>}
*/
function issueAjaxRequest(verb, path, elt, event, etc, confirmed) {

htmx/src/htmx.js

Lines 4288 to 4299 in 03c3af7

const confirmQuestion = getClosestAttributeValue(elt, 'hx-confirm')
// allow event-based confirmation w/ a callback
if (confirmed === undefined) {
const issueRequest = function(skipConfirmation) {
return issueAjaxRequest(verb, path, elt, event, etc, !!skipConfirmation)
}
const confirmDetails = { target, elt, path, verb, triggeringEvent: event, etc, issueRequest, question: confirmQuestion }
if (triggerEvent(elt, 'htmx:confirm', confirmDetails) === false) {
maybeCall(resolve)
return promise
}
}

htmx/src/htmx.js

Lines 4395 to 4401 in 03c3af7

if (confirmQuestion && !confirmed) {
if (!confirm(confirmQuestion)) {
maybeCall(resolve)
endRequestLock()
return promise
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions