Replies: 7 comments 5 replies
-
|
Hi, made some progress where in able to display modal and then on submit if proper otp it delete row but it does not remove the dialog. it just removed the close button of modal and then ui is blocked. Also if error (422 returned) ui is blocked. any ideas how to implement this correctly ? fastapi endpoint otpmodal.html event handler javascript: |
Beta Was this translation helpful? Give feedback.
-
|
use case: I have list of games and for each row I have option to delete. we show confirm box for delete click and then if it succeeds the row gets deleted and on error it shows error. now I am adding OTP confirm for delete click. If you have example of using events in specific manner please share. I am currently using beforeSwap on body for every thing pretty much. I now added HX-Trigger header on success as in code below I still have things not quite as expected. The Close button part disappears on success of OTP match but dialog stays upto submit button. In case of OTP verify failure the same close button disappears and modal becomes unresponsive or never submits may be some target is invalid which causes it. I think you hinting to learn hyperscript and may be its time to take look.
|
Beta Was this translation helpful? Give feedback.
-
|
issue was that I did not include hyperscript so modal related close click was not working. here is body beforeswap event handler updated: fastapi endpoint: issues:
|
Beta Was this translation helpful? Give feedback.
-
|
I have now used #aside but the row deletion is not working. seems the confirmed event is not reaching TR element. without #aside had issue that on showing modal the row would delete beforehand. after #aside change one thing though is that those TR and DIV case below seems not needed and I can delete them. here is how now I send multiple events. I had to add div#aside to modal though. we unable to specify like innerHTML swap behaviour so have to add this div. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @imiten, A couple things: first, I should tell you that I'm not so familiar with Python, so it is probably easier for me if you can share what your server is sending back and forth, instead of the source code that generates the HTTP documents. Also, it's really easy to miscommunicate over email threads like this, and I think we may have been miscommunicating about the order of events for your modal dialogs. To try to cut through this, I'm going to describe the process in my app step-by-step, and how I think it relates to your project. If I miss something, please forgive me :)
Here's some sample code for this whole thing. I'm typing it by hand, so there will probably be typos/bugs in the specifics. But, it should help you understand the pattern: ORIGINAL PAGE <!-- BEGIN "chrome" wrapper header, including global nav, CSS, scripts, etc (this is just a demo/placeholder)-->
<html>
<head>
<script src="https://unpkg.com/htmx.org"></script>
<script src="https://unpkg.com/hyperscript.org"></script>
<link rel="stylesheet" href="https://the.missing.style"/>
</head>
<body>
<nav>
<a href="">Home</a>
<a href="">About</a>
etc ...
</nav>
<!-- END "chrome" wrapper header-->
<!-- BEGIN "inner" page. This can be returned separately by the server, without the "chrome" wrapper above and below -->
<div hx-get="http://myserver.com/people?view=table" hx-trigger="refreshPage from:window">
<table>
<tr>
<td>John Connor</td>
<td>
<button hx-get="https://myserver.com/people/john-connor/delete">Delete?</button>
</td>
</tr>
</table>
</div>
<!-- END "inner" page -->
<!-- BEGIN "chrome" wrapper footer -->
<aside></aside>
</body>
</html>
<!-- END "chrome" wrapper footer -->MODAL DIALOG <div id="modal" _="on closeModal add .closing then wait for animationend then remove me">
<div class="modal-underlay" _="on click trigger closeModal"></div>
<div class="modal-content">
<h1>Modal Dialog</h1>
<form id="otpform" class="ui form" hx-post="https://myserver.com/people/john-connor/delete">
Delete <b>John Connor</b>?
<button class="ui button primary" type="submit">Delete</button>
<button type="button" script="on click trigger closeModal">Cancel</button>
</form>
</div>
</div>The server can now just return an empty document along with the response header Does this make sense? I hope so. I'm sure you'll need to do some tweaking to this so that it better fits your specific app and API, but hopefully this helps you understand the pattern that I'm using, and is working out really great in my apps. Best wishes! |
Beta Was this translation helpful? Give feedback.
-
|
Hi @benpate, Thanks for sharing your pattern. I was thinking on similar lines that I will have to give up on existing pattern that I am using from examples.
By original example it was all working fine when I did not have OTP modal in the flow. Now as I have added check as below and I return OTP modal I want to prevent the original case where in on response of success from that call it will delete row: here see I try to prevent client to interpret it as success by returning 422 and so now row is not deleting as I am also using #aside and ReTarget. Now when OTP modal is submiitted and entered otp maches I return 200 and two events closeModal and confirmed (assuming that confirmed will lead to row deletion from UI) but row is not getting deleted making me feel that that original setup of Delete Row is lost in the process of #aside and ReTarget. So now I was thinking to add id to each TR and when I revert with confirmed event send it back. That id can be same as game.id. Thus then may be in javascript event handler for confirmed event I can intercept and remove that TR explicitly. Also I see you using refreshPage event that is some thing new I learned. I was not thinking about it to may be try to not have to reload most of page and use AJAX but refreshPage as such also is using AJAX seems on just that DIV though it will be sort of top level div of SPA. I hope I gave you insight into where I am now. With #aside and ReTarget I am able to cleanup some javascript but am loosing that original framework of DeleteRow example which was working fine for me without OTP Modal. If I do not use #aside and ReTarget I see that the row gets deleted when I show OTP Modal even for status of 422. original event path without ReTarget was TR: now its otpform which I want to point back to TR so it may act on it: Regards ! |
Beta Was this translation helpful? Give feedback.
-
|
Hi, I gave some thought and first decided to try what you suggested instead of figuring out and debugging details of htmx and its events etc. I tried monitorEvent and htmx.logAll but could not make much sense. what you suggested works for now. here are changes I made to that otp related flow and confirm, modal and deletion (refresh games list) all work fine. that from:window trick is also new learning. thanks for sharing your time and knowledge. main.py endpoint gamelist.html partial I was now thinking since I am not really using DeleteRow example in true sense that delete animation is not shown how can I instead replace it with Confirm example instead. I see some confirmed event in that example may be I can try that. If clicked yes in that example it will fire /confirmed which I can replace with my delete url and assume it will all work. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
https://htmx.org/examples/modal-custom/ mentions how to popup modal diaglog with some content and have it close but its not using javascript but hyperscript it seems. It says you can also use javascript for it but where is documentation for it or sample for it ?
I am looking into using example of custom modal dialog and want to have "OTP submit form" as its content. can one provide example ? i am unable to understand how to handle invalid otp response, on success how to close the dialog etc.
I may use pyotp on server side using fastapi to provide otp to client.
here is server side pseudo code:
Below is row line of list where in delete button click will cause confirm box and then delete action on server.
row_ro.html
below is OTP form in custom dialog I also want to trigger OTP send call on server so how to do that also in below example ? basically on loading this below partial i want to trigger OTP generation on server which will be its own endpoint.
Beta Was this translation helpful? Give feedback.
All reactions