I would like to add an option to have the ajax response display the same form again after submission.

We have a use-case where the user will repeat submission of the form until a condition is met, and the form will be modified each time based on previous submissions.

Comments

John Pitcairn created an issue. See original summary.

johnpitcairn’s picture

I see there is a TODO in the module code ;-)

ziomizar’s picture

Hi John Pitcairn,

This is something that i would to have on this module, but i just let a comment on the code because this functionality seems to be more tricky that i thought.

If someone have suggestions or ideas on how to implement it correctly is welcome.

johnpitcairn’s picture

Could you post a bit about what you already tried, and why it turned out to be tricky?

johnpitcairn’s picture

Status: Active » Needs review
StatusFileSize
new8.54 KB

This patch works for me.

I have renamed the CONTACT_AJAX_LOAD_FORM constant to CONTACT_AJAX_LOAD_DEFAULT_MESSAGE, and that remains the default. This will ensure no sites have the form appearing unexpectedly.

There is a new setting option, "Default message and empty form" which will reload a clean form with any system messages above it.

Status: Needs review » Needs work

The last submitted patch, 5: contact_ajax-reload-form-2846891-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnpitcairn’s picture

StatusFileSize
new10.05 KB

Didn't update the changed constant in the tests. Try this one.

johnpitcairn’s picture

Status: Needs work » Needs review
ziomizar’s picture

Hi John Pitcairn, many thanks to work on this!

I haven't tested it yet but looking into the code i noticed to main things:
1. You are using tabs instead of spaces. Coding standard needs 2 spaces instead of a tab.
2. Why this has been removed?

+++ b/contact_ajax.module
@@ -224,73 +233,93 @@ function contact_ajax_form_contact_message_form_alter(&$form, &$form_state, $for
-
-  if (\Drupal::moduleHandler()->moduleExists('views')) {
-    $response->addCommand(new ScrollTopCommand($render_selector));
-  }
-
johnpitcairn’s picture

1 - I don't think PhpStorm correctly set the project style. Will fix.
2 - Accident. Will fix.

johnpitcairn’s picture

Status: Needs review » Needs work
johnpitcairn’s picture

Status: Needs work » Needs review
StatusFileSize
new6.86 KB

And fixed, I think.

  • ziomizar committed a45e091 on 8.x-1.x authored by John Pitcairn
    Issue #2846891 by John Pitcairn: Option to display the form again after...
ziomizar’s picture

Status: Needs review » Fixed

Pushed on 8.x-1.x-dev. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.