Skip to content
This repository

deform.Form() with use_ajax=True will not use ajax after second submit #1

Merged
merged 1 commit into from almost 3 years ago

2 participants

Patrick Gerken Chris McDonough
Patrick Gerken

A submit will overwrite the form.
After that there are no event handlers registered any longer to submit the form via ajax.
To reproduce the issue, go to:
http://deformdemo.repoze.org/ajaxform/

and submit the form twice with empty data. the second submit will reload the page.

Fix for issue 1 bd9657f
Chris McDonough mcdonc merged commit bd9657f into from June 23, 2011
Chris McDonough mcdonc closed this June 23, 2011
Chris McDonough
Owner
mcdonc commented June 23, 2011

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 22, 2011
Fix for issue 1 bd9657f
This page is out of date. Refresh to see the latest.
13  deform/form.py
@@ -63,8 +63,17 @@ class Form(field.Field):
63 63
 
64 64
        Default options exist even if ``ajax_options`` is not provided.
65 65
        By default, ``target`` points at the DOM node representing the
66  
-       form and and ``replaceTarget`` is ``true``.  If you pass these
67  
-       values in ``ajax_options``, the defaults will be overridden.
  66
+       form and and ``replaceTarget`` is ``true``. A successhandler calls
  67
+       the deform_ajaxify method that will ajaxify the newly written form
  68
+       again. the deform_ajaxify method is in the global namespace, it
  69
+       requires a oid, and accepts a method. If it receives a method,
  70
+       it will call the method after it ajaxified the form itself.
  71
+       If you pass these values in ``ajax_options``, the defaults will
  72
+       be overridden.
  73
+       If you want to override the success handler, don't forget to
  74
+       call the original deform_ajaxify successhandler, and pass your
  75
+       own method as an argument. Else, subsequent form submissions
  76
+       won't be submitted via AJAX.
68 77
 
69 78
        This option has no effect when ``use_ajax`` is False.
70 79
 
40  deform/templates/form.pt
@@ -53,22 +53,32 @@
53 53
   </fieldset>
54 54
 
55 55
 <script type="text/javascript" tal:condition="field.use_ajax">
  56
+  function deform_ajaxify(response, status, xhr, form, oid, mthd){
  57
+     var options = {
  58
+       target: '#' + oid,
  59
+       replaceTarget: true,
  60
+       success: function(response, status, xhr, form){
  61
+         deform_ajaxify(response, status, xhr, form, oid);
  62
+       }
  63
+     };
  64
+     var extra_options = ${field.ajax_options};
  65
+     var name;
  66
+     if (extra_options) {
  67
+       for (name in extra_options) {
  68
+         options[name] = extra_options[name];
  69
+       };
  70
+     };
  71
+     $('#' + oid).ajaxForm(options);
  72
+     if(mthd){
  73
+       mthd(response, status, xhr, form);
  74
+     }
  75
+  }
56 76
   deform.addCallback(
57 77
      '${field.formid}',
58  
-     function(oid) { 
59  
-         var options = {
60  
-           target: '#' + oid,
61  
-           replaceTarget: true,
62  
-         };
63  
-         var extra_options = ${field.ajax_options};
64  
-         var name;
65  
-         if (extra_options) {
66  
-           for (name in extra_options) {
67  
-             options[name] = extra_options[name];
68  
-           };
69  
-         };
70  
-         $('#' + oid).ajaxForm(options);
71  
-   });
  78
+     function(oid) {
  79
+       deform_ajaxify(null, null, null, null, oid);
  80
+     }
  81
+  );
72 82
 </script>
73  
-  
  83
+
74 84
 </form>
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.