Has anyone successfully created a ctools wizard form that moves between steps with ajax? If so, can documentation be provided on the steps needed to implement?
Issue:
When attempting to move between steps on a wizard form with ajax enabled, a 500 error occurs when hitting the "next" button.
Drupal\Core\Form\FormAjaxException: in Drupal\Core\Form\FormBuilder->buildForm() (line 334 of /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php).
To reproduce:
When i was attempting to make this work, I simply copied the ctools_wizard_test module into my modules directory and modified the routing.yml. I added js: 'ajax'
to the ctools.wizard.test.step and ctools.wizard.test routes after finding line 77 of WizardFormController.php that seemed to indicate adding that info to the routing would cause the form to work via ajax.
ctools.wizard.test:
path: '/ctools/wizard'
defaults:
_wizard: '\Drupal\ctools_wizard_test\Wizard\WizardTest'
_title: 'Wizard Test'
tempstore_id: 'ctools.wizard.test'
machine_name: 'WizardTest'
js: 'ajax'
requirements:
_access: 'TRUE'
ctools.wizard.test.step:
path: '/ctools/wizard/{step}'
defaults:
_wizard: '\Drupal\ctools_wizard_test\Wizard\WizardTest'
_title: 'Wizard Test'
tempstore_id: 'ctools.wizard.test'
machine_name: 'WizardTest'
js: 'ajax'
requirements:
_access: 'TRUE'
I was intially attempting to get this whole thing to work within a modal so i additionally created a new route and controller that simply outputs a button that opens the ctools.wizard.test route in a modal. This does cause step one of the form to load in a modal, but the same error occurs when attempting to hit "next".
I have tried this with core versions 8.2.7 and 8.3.0.
At this point, im not sure if there is a bug or if I am missing something required to make this work correctly. Any assistance would be greatly appreciated.
Comment | File | Size | Author |
---|---|---|---|
#10 | interdiff_2-10.txt | 478 bytes | anagomes |
#10 | 2867422-10.patch | 1.61 KB | anagomes |
#2 | 2867422-fix-wizzard-ajax-steps-fix.patch | 2.01 KB | csechols |
Screen Shot 2017-04-06 at 9.44.53 AM.png | 32.33 KB | morseCode |
Comments
Comment #2
csechols CreditAttribution: csechols at AAA commentedHere is a patch that fixes this issue from my testing. Inside FormWizardBase.php, the submitForm() and previous() methods were lacking the logic for switching steps when ajax is being used.
Comment #3
Lukas von BlarerThe patch didn't fix my the error in my case.
Comment #4
jmoreira CreditAttribution: jmoreira commentedPatch on #2 works for me.
Comment #5
shubham.prakash CreditAttribution: shubham.prakash at OpenSense Labs commentedComment #6
gonssalI can confirm that the patch works and still applies.
There's a new function
getPrevOp()
that is not used and could be removed, but there's alsogetNextOp()
so it can be left there.In my case I didn't want to use modal dialogs so I'm replacing the entire forms instead.
Comment #7
thallesThe patch is applicable and apparently already was tested
Comment #8
joelpittetshould be removed if it's not used.
Comment #9
anagomes CreditAttribution: anagomes at CI&T commentedComment #10
anagomes CreditAttribution: anagomes at CI&T commentedComment #11
paulocsJust tested the patch #10 locally and it is working as expected...
I was able to move between the pages via ajax. The code looks good as well.
Comment #13
japerry