Question

I had an html file with form as below

<html>
  <head> 
    <title>Create a product</title>
  </head>
  <body>
     <form  action="/submit/form/" method="POST">
         <input name="text" placeholder="Email please"/>

         <input name="" type="submit" class="btn btn-large big_btn " value="Save Changes">
<input id="cancel_profile_changes" name="" type="button" class="btn btn-large big_blkbtn hide_margtp_35_a " value="Cancel">
     </form>
  <body>
</html> 

When a user submit the forms it will redirected to action attribute url, but whan a user clicks on cancel a pop up dialog should open with a message Are u sure u want to discard changes with ok and cancel.

So when the user clicks on the Ok, he should be redirected to a url /dashboard/, if he clicks cancel, then he should be in the same page without redirecting and without loosing the form data

So how to achieve the above functionality with twitter bootstrap very easily, i am using bootbox.js for this kind of functionality until now, but because of design implementations i only want to use only twitter bootstrap ?

so how to achive the above functionality with twitter bootstrap ?

Was it helpful?

Solution

Attach a modal to the cancel button..

<form action="/submit/form/" method="POST">
  <input name="text" placeholder="Email please">

  <input name="" type="submit" class="btn btn-large big_btn " value="Save Changes">
  <input href="#modal-dialog" data-toggle="modal" id="cancel_profile_changes" type="button" class="btn btn-large big_blkbtn hide_margtp_35_a" value="Cancel">
</form>

<div id="modal-dialog" class="modal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
            <a href="#" data-dismiss="modal" aria-hidden="true" class="close">×</a>
             <h3>Are you sure</h3>
        </div>
        <div class="modal-body">
             <p>Do you want to discard changes?</p>
        </div>
        <div class="modal-footer">
          <a href="#" data-dismiss="modal" id="btnConfirm" class="btn confirm">OK</a>
          <a href="#" data-dismiss="modal" aria-hidden="true" class="btn secondary">Cancel</a>
        </div>
      </div>
    </div>
</div>

Demo: http://bootply.com/93435

OTHER TIPS

Try the following once..

<!-- Button to trigger modal -->
<input id="cancel_profile_changes" name="" type="button" class="btn btn-large big_blkbtn hide_margtp_35_a " value="Cancel" data-toggle="modal" href="#myModal">


<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<!-- this will close the popup -->
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <!-- here navigate to other page -->
<button class="btn btn-primary">Save changes</button>
</div>
</div>

FMI: http://getbootstrap.com/2.3.2/javascript.html#modals

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top