@@ -312,32 +312,34 @@ a <div class="row">
312312
313313 {% if event .is_test_mode %}
314314 <script >
315- document .getElementById (' simulateDonationForm' )? .addEventListener (' submit' , async function (e ) {
316- e .preventDefault ();
317- const pseudo = document .getElementById (' sim_pseudo' ).value ;
318- const amount = Math .round (parseFloat (document .getElementById (' sim_amount' ).value ) * 100 );
319- const message = document .getElementById (' sim_message' ).value ;
320- const alertBox = document .getElementById (' simulateAlert' );
315+ document .addEventListener (' DOMContentLoaded' , function () {
316+ document .getElementById (' simulateDonationForm' )? .addEventListener (' submit' , async function (e ) {
317+ e .preventDefault ();
318+ const pseudo = document .getElementById (' sim_pseudo' ).value ;
319+ const amount = Math .round (parseFloat (document .getElementById (' sim_amount' ).value ) * 100 );
320+ const message = document .getElementById (' sim_message' ).value ;
321+ const alertBox = document .getElementById (' simulateAlert' );
321322
322- try {
323- const resp = await fetch (' /widget-event/{{ event.guid }}/simulate' , {
324- method: ' POST' ,
325- headers: {' Content-Type' : ' application/json' },
326- body: JSON .stringify ({ pseudo, amount, message })
327- });
328- const json = await resp .json ();
329- if (resp .ok ) {
330- document .getElementById (' testAmountDisplay' ).textContent = (json .amount / 100 ).toLocaleString (' fr-FR' , {minimumFractionDigits: 2 }) + ' €' ;
331- alertBox .innerHTML = ' <div class="alert alert-success alert-dismissible fade show py-1 px-2 mb-0"><small>✅ Don simulé : ' + pseudo + ' — ' + (amount/ 100 ) + ' €</small><button type="button" class="btn-close btn-close-sm" data-bs-dismiss="alert"></button></div>' ;
332- alertBox .style .display = ' block' ;
333- } else {
334- alertBox .innerHTML = ' <div class="alert alert-danger py-1 px-2 mb-0"><small>❌ ' + (json .error || ' Erreur' ) + ' </small></div>' ;
323+ try {
324+ const resp = await fetch (' /widget-event/{{ event.guid }}/simulate' , {
325+ method: ' POST' ,
326+ headers: {' Content-Type' : ' application/json' },
327+ body: JSON .stringify ({ pseudo, amount, message })
328+ });
329+ const json = await resp .json ();
330+ if (resp .ok ) {
331+ document .getElementById (' testAmountDisplay' ).textContent = (json .amount / 100 ).toLocaleString (' fr-FR' , {minimumFractionDigits: 2 }) + ' €' ;
332+ alertBox .innerHTML = ' <div class="alert alert-success alert-dismissible fade show py-1 px-2 mb-0"><small>✅ Don simulé : ' + pseudo + ' — ' + (amount/ 100 ) + ' €</small><button type="button" class="btn-close btn-close-sm" data-bs-dismiss="alert"></button></div>' ;
333+ alertBox .style .display = ' block' ;
334+ } else {
335+ alertBox .innerHTML = ' <div class="alert alert-danger py-1 px-2 mb-0"><small>❌ ' + (json .error || ' Erreur' ) + ' </small></div>' ;
336+ alertBox .style .display = ' block' ;
337+ }
338+ } catch (err) {
339+ alertBox .innerHTML = ' <div class="alert alert-danger py-1 px-2 mb-0"><small>❌ Erreur réseau</small></div>' ;
335340 alertBox .style .display = ' block' ;
336341 }
337- } catch (err) {
338- alertBox .innerHTML = ' <div class="alert alert-danger py-1 px-2 mb-0"><small>❌ Erreur réseau</small></div>' ;
339- alertBox .style .display = ' block' ;
340- }
342+ });
341343 });
342344 < / script>
343345 {% endif % }
0 commit comments