Open modal on succesful mail

3 replies · opened Jul 7, 2023

DDavegdrJul 7, 2023

Hello Semicolon

I tried to add the following based on an "old" jquery example you provided:

				[](#myModal1)
				<div class="modal1 mfp-hide" id="myModal1">
					<div class="block mx-auto" style="background-color: #FFF; max-width: 600px;">
						<div class="center clearfix" style="padding: 50px;">
						</div>
					</div>
				</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
var templateContactForm = document.querySelector('#template-contactform');

templateContactForm.addEventListener('formSubmitSuccess', function() {
var feedbackFormSuccessModal = document.querySelector('.feedback-form-success-modal');
feedbackFormSuccessModal.classList.add('open');
});
});

&lt;/script&gt;

However the functions does not open the modal. Can you provide a solution?

PS: the documentation still mentions the JQUERY and not the vanilla JS.

SSemicolon WebSTAFFJul 10, 2023

Hello,

Thanks for your Patience!

Consider following the Steps below:

  1. Suppose this is your Modal Code:
    [ch_pre]
    Launch modal

             Modal Heading
             
         
         
             ...
         
         
             Close
             Save changes

[/ch_pre]

Notice, that the data-bs-target="#myModal" is required. You can simply hide it by adding he .d-none Class on the ``.

  1. Use the following JS Code to open the Modal:
    [ch_pre type="js"]document.addEventListener('DOMContentLoaded', function() {
    var templateContactForm = document.querySelector('#template-contactform');

    templateContactForm.addEventListener('formSubmitSuccess', function() {
    var modalTrigger = document.querySelector('[data-bs-target="#myModal"]');
    var modal = bootstrap.Modal.getOrCreateInstance('#myModal');
    modal.show(modalTrigger);

    });
    });[/ch_pre]

This should definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

PS. We will update the Documentations shortly.

SSemicolon WebSTAFFJul 15, 2023

Hello,

Thanks for your Patience!

Looks like there are some issues triggering the events with Vanilla JS, we are checking for what is exactly causing this. Meanwhile, please consider using this code instead:
[ch_pre type="js"]SEMICOLON.Core.isFuncTrue(function() {
return typeof jQuery !== 'undefined' && typeof bootstrap !== 'undefined';
}).then( function(cond) {
if( !cond ) {
return false;
}

jQuery('#template-contactform').on('formSubmitSuccess', function() {
	var modalTrigger = document.querySelector('[data-bs-target="#myModal"]');
	var modal = bootstrap.Modal.getOrCreateInstance('#myModal');
	modal.show(modalTrigger);
});

});[/ch_pre]

This should work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard