Skip to content

Loading…

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

Merged
merged 1 commit into from

2 participants

@do3cc

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.

Patrick Gerken Fix for issue 1 bd9657f
@mcdonc mcdonc merged commit bd9657f into Pylons:master
@mcdonc
Pylons Project member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2011
  1. Fix for issue 1

    Patrick Gerken committed
Showing with 36 additions and 17 deletions.
  1. +11 −2 deform/form.py
  2. +25 −15 deform/templates/form.pt
View
13 deform/form.py
@@ -63,8 +63,17 @@ class Form(field.Field):
Default options exist even if ``ajax_options`` is not provided.
By default, ``target`` points at the DOM node representing the
- form and and ``replaceTarget`` is ``true``. If you pass these
- values in ``ajax_options``, the defaults will be overridden.
+ form and and ``replaceTarget`` is ``true``. A successhandler calls
+ the deform_ajaxify method that will ajaxify the newly written form
+ again. the deform_ajaxify method is in the global namespace, it
+ requires a oid, and accepts a method. If it receives a method,
+ it will call the method after it ajaxified the form itself.
+ If you pass these values in ``ajax_options``, the defaults will
+ be overridden.
+ If you want to override the success handler, don't forget to
+ call the original deform_ajaxify successhandler, and pass your
+ own method as an argument. Else, subsequent form submissions
+ won't be submitted via AJAX.
This option has no effect when ``use_ajax`` is False.
View
40 deform/templates/form.pt
@@ -53,22 +53,32 @@
</fieldset>
<script type="text/javascript" tal:condition="field.use_ajax">
+ function deform_ajaxify(response, status, xhr, form, oid, mthd){
+ var options = {
+ target: '#' + oid,
+ replaceTarget: true,
+ success: function(response, status, xhr, form){
+ deform_ajaxify(response, status, xhr, form, oid);
+ }
+ };
+ var extra_options = ${field.ajax_options};
+ var name;
+ if (extra_options) {
+ for (name in extra_options) {
+ options[name] = extra_options[name];
+ };
+ };
+ $('#' + oid).ajaxForm(options);
+ if(mthd){
+ mthd(response, status, xhr, form);
+ }
+ }
deform.addCallback(
'${field.formid}',
- function(oid) {
- var options = {
- target: '#' + oid,
- replaceTarget: true,
- };
- var extra_options = ${field.ajax_options};
- var name;
- if (extra_options) {
- for (name in extra_options) {
- options[name] = extra_options[name];
- };
- };
- $('#' + oid).ajaxForm(options);
- });
+ function(oid) {
+ deform_ajaxify(null, null, null, null, oid);
+ }
+ );
</script>
-
+
</form>
Something went wrong with that request. Please try again.