You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For anyone who wants hx-prompt functionality, and the official extension is not working due to needing async custom dialogs, I've hacked in this solution, based on hx-confirm.
Just define an event handler for htmx:prompt and handle things just like if it was htmx:confirm.
document.addEventListener('htmx:prompt',(event)=>{event.preventDefault()letprompt=event.detail.ctx.promptif(!prompt)event.detail.dropRequest()// Using my own custom prompt dialog lib.Prompt.call(prompt,'',(answer)=>{if(answer)returnevent.detail.issueRequest(answer)event.detail.dropRequest()})})
This still falls back to window.prompt if no custom handler is defined. And since hx-confirm happens right before it, they can be combined to confirm and then use a prompt.
I might do a PR down the line when I get more free time, as I wish this was just included in the base.
396a397> prompt: this.#attributeValue(sourceElement, "hx-prompt"),568a570,588> }>> if (ctx.prompt) { > let result = await new Promise(resolve => {> let detail = { > ctx,> issueRequest: (answer) => resolve(answer),> dropRequest: () => resolve(false)> };>> if (this.#trigger(elt, "htmx:prompt", detail)) {> let js = this.#extractJavascriptContent(ctx.prompt);> resolve(js ? this.#executeJavaScript(elt, {ctx}, js, true) : window.prompt(ctx.prompt));> }; > });>> if (!result) return;>> ctx.request.headers['HX-Prompt'] = encodeURI(result);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Hello,
For anyone who wants
hx-promptfunctionality, and the official extension is not working due to needing async custom dialogs, I've hacked in this solution, based onhx-confirm.Just define an event handler for
htmx:promptand handle things just like if it washtmx:confirm.This still falls back to
window.promptif no custom handler is defined. And sincehx-confirmhappens right before it, they can be combined to confirm and then use a prompt.I might do a PR down the line when I get more free time, as I wish this was just included in the base.
All reactions