oleg.foreigner
oleg.foreigner

Reputation: 1023

JavaScript confirm dialog in Django

I have a Django form. And I need a confirm/cancel dialog on form submit. A had an idea of sending POST data from jQuery... but is it a way to use javascript dialog as middleware?

Upvotes: 0

Views: 6236

Answers (1)

kartheek
kartheek

Reputation: 6684

Add the bellow code according to your need in your Html

<form><input type="submit" value="Submit" id="confirm"/> </form>

and jQuery code for confirm dialog

<script>
    jQuery("#confirm").click(function(){
        $("<div></div>").appendTo('body')
           .html('<div><h3> write your message for confirm dialog</h3></div>')
           .dialog({
                title: "Confotm Dialog" ,
                width:500, height:300,
                modal:true,
                resizable: false, 
                show: { effect: 'drop', direction: "left" }, 
                hide:{effect:'blind'}

                buttons: {
                    Yes: function() {
                          jQuery.ajax({
                              type:"POST", //post data
                              data:{'key':key}, //if you want to send any data to view 
                              url:'/get_viewerModal/' // your url that u write in action in form tag
                          }).done(function(result){
                               alert("am done") //this will executes after your view executed  
                          })
                     },
                    Cancel: function() {
                        $( this ).dialog( "close" );
                    }
               }
           });
    });
<script> 

here you need ajax knowledge and it is very easy to use am sure you do this :)

Upvotes: 3

Related Questions