I would like my modal's submit button to bring my users to my contact form outside of the modal and to close the modal in the process.
I've tried several ideas but so far, I am scrolling to the element wanted but when the modal closes it scrolls back to the element where my modal is initially located.
Modal :
<div class="modal fade" id="Modal-<?= $formation['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button>
</div>
<div class="modal-body">
<?= $formation['descriptionLongue'] ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
<button type="button" class="btn btn-primary devis">Demander un devis</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<!-- FORMATION -->
Contact Form
<div class="container col-4" id="contact">
<!-- form contact -->
<form class="text-center border border-light p-5" action="<?=buildUrl('/contact');?>" method="POST">
etc...
Javacript
const target = document.getElementById('contact'),
buttons = document.querySelectorAll('.devis');
for (const button of buttons) {
button.addEventListener('click', function(){
$(this).parents('.modal').modal('hide');
target.scrollIntoView({
block: 'start',
behavior: 'smooth',
inline: 'nearest'
});
});
}
Related
I have multiple forms on my site that are loaded in a Bootstrap Modal on a click of a button. For some reason when I try to submit the forms nothing happens. I have checked the browser console and I can't find any errors. Also there is no error in the error_log file.
The code below is what I have for my forms. Have I done something wrong?
Edit: I have tested with another form and it seems javascript/jquery is not being loaded in the modal.
<button type="button" class="application_button button" data-toggle="modal" data-target="#jobapplyform">
<?php esc_attr_e( 'Apply for job', 'wp-job-manager' ); ?>
</button>
<div class="modal fade" id="jobapplyform" tabindex="-1" role="dialog" aria-labelledby="jobModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close-btn-modal" data-dismiss="modal" aria-label="Close">
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/close-icon.png"/>
</button>
<h2 class="modal-title" id="jobModalLabel">Apply</h2>
</div>
<div class="modal-body">
<div class="application_details">
<?php echo do_shortcode('[contact-form-7 id="5096" title="Claim This Profile"]'); ?>
</div>
</div>
</div>
</div>
</div>
May be you are using bootstrap4.
Please try bellow code
<!-- The Modal -->
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#jobapplyform">
Open modal
</button>
<div class="modal" id="jobapplyform">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close-btn-modal" data-dismiss="modal" aria-label="Close"><img src="<?php echo get_stylesheet_directory_uri(); ?>/img/close-icon.png"/></button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="application_details">
<?php echo do_shortcode('[contact-form-7 id="5096" title="Claim This Profile"]'); ?>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
If there is not visibility issue then please try to prevent close when submit button and check if contact form submit button action triggered.
You are missing form element for HTML and type submit for the button, or else the info wont be sent anywhere.
i have a modal and i try to implement nested comments
now i want to send the parent comment id to child comment in modal
button that show modal:
<button class="btn btn-xs btn-light" data-target="#commentModal" data-toggle="modal" data-parent="3">پاسخ</button>
<div class="modal fade" id="commentModal" tabindex="-1" role="dialog" aria-labelledby="commentModal" aria-hidden="true" dir="rtl">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
<h4 id="modal-label-3" class="modal-title">ارسال نظر</h4>
</div>
<div class="modal-body">
<div class="respond-form" id="respond" style="padding-top: 0">
<form action="/comment" class="form-gray-fields">
{{ csrf_field() }}
<input type="hidden" name="parent_id" value="0">
<br>
<div class="row">
<div class="col-md-12">
<div class="form-group text-center">
<button class="btn btn-block" type="submit">ثبت دیدگاه</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
i want to send value of data-parent in button, to "vlaue" attribute of input in modal
i see this for bootstrap modals:
$('#commentModal').on('show.bs.modal' , function (event) {
let button = $(event.relatedTarget);
let parentId = button.data('parent');
let modal = $(this);
modal.find("[name='parent_id']").val(parentId);
});
but i do not use bootstrap and following code not working for me!
How about something like this?
$(".btn").on("click", function(){
$(".modal-body").find("[name=parent_id]").val($(this).data("parent"));
// Code to show modal
});
I have a dialog box which should appear whenever I click on a checkbox. But it should not disappear when clicking outside or pressing escape. so I used backdrop='static' , keyboard='false' in my jquery.
but then this dialog box is appearing whenever I load or refresh the page.
$('#storeStatusDialog').modal({
backdrop: 'static',
keyboard: false
})
<div class="container">
<div class="modal fade" id="storeStatusDialog" role="dialog" >
<div class="modal-dialog armanlast">
<div class="modal-content">
<div class="modal-header">
<div class="close-icon-wrap">
<a class="modal-close-icon" href="#" data-dismiss="modal">×</a>
</div>
</div>
<div class="modal-body">
<h1 class="modal-title1">Deactivate Store</h1>
<p class="deactivate-p"></p>
</div>
<div class="modal-footer">
<button type="button" id="noDeactivate" data-dismiss="modal" class="btn btn-default cancel-confirm1 btn-approval1" onclick="statusOnAgain()">Cancel</button>
<button type="button" id="yesDeactivate" class="btn btn-default confirm-complete1 btn-approval1"><span style="horizontal-align:middle">Yes</span></button>
</div>
</div>
</div>
</div>
</div>
Please tell me a way to prevent dialog box appearing when page gets loaded.
thank you so much.
HTML:
<div class="container">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#storeStatusDialog">
Launch
</button>
<div class="modal fade" id="storeStatusDialog" role="dialog">
<div class="modal-dialog armanlast">
<div class="modal-content">
<div class="modal-header">
<div class="close-icon-wrap">
<a class="modal-close-icon" href="#" data-dismiss="modal">×</a>
</div>
</div>
<div class="modal-body">
<h1 class="modal-title1">Deactivate Store</h1>
<p class="deactivate-p"></p>
</div>
<div class="modal-footer">
<button type="button" id="noDeactivate" data-dismiss="modal" class="btn btn-default cancel-confirm1 btn-approval1" onclick="statusOnAgain()">Cancel</button>
<button type="button" id="yesDeactivate" class="btn btn-default confirm-complete1 btn-approval1"><span style="horizontal-align:middle">Yes</span>
</button>
</div>
</div>
</div>
</div>
</div>
Js:
$('#storeStatusDialog').modal({
show: false,
backdrop: 'static',
keyboard: false
})
Snippet:
http://codepen.io/anon/pen/dpEjxK
I've currently got a while loop that echos all the information in my database onto a table. In this table there is a button that can be clicked to link to a modal.
<a data-toggle="modal" data-target="#myModal2" class="active"><img src="img here"></a>
This then links to a modal with the code:
<div class="modal fade" id="myModal2" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<?php echo $row['name']; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
What I'm trying to do is print out some of that information from the while loop into that modal e.g.($row['name']). How can I do this? Can this be done through PHP or does it have to be JS?
I'm using Bootstrap CSS and I have a form with glyphicons next to each person.
Like that :
I would like when I click on the Tag glyphicons it popups something like that :
The visitor write something inside it and press OK then it goes to another page for UPDATE the note from Alexis.
How can we do a similar popups and when pressing OK it is like an OK ?
You can Try something like this:
Click this link for more details: -
http://www.bootply.com/X4oaJWOzOi
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
<span class="glyphicon glyphicon-trash">LName FNmae</span>
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Note</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>