Drupal 8: Multistep ajaxified form in a modal window -
task description:
i need open modal window url location hash i.e.
www.example.com#overlay=my-multistep-form (pretty same d7 overlay module does). window should contain multi-step ajaxified form,
so use
drupal.behaviors.rf_overlay = { attach: function(context, settings) { // overlay url if (location.hash.indexof('#overlay') >= 0) { var event = { data: {} }; // special route multistep forms if (location.hash.indexof('#overlay=become-a-sales-partner') >= 0) { event.data.url = '/overlay/partner-form'; openmultistepformmodal(event); } } function openmultistepformmodal(event) { drupal.ajax({ url: event.data.url, success: function(response) { var content = ''; (var in response) { if (response[i].data != undefined) { content += response[i].data; } } $('.modal-body').empty(); var $overlaycontent = $('<div>' + content + '</div>').appendto('.modal-body'); drupal.dialog($overlaycontent, {}); $("#drupal-modal").addclass('overlay-' + event.data.url).modal(); } }).execute(); } } };
i have form controller @ /overlay/partner-form route, returns form array according specified step
public function buildform(array $form, formstateinterface $form_state, array $options = array()) { $step = in_array($form_state->get('step'), array(1, 2)) ? $form_state->get('step') : 1; $form_state->set('step', $step); switch ($step) { case 1: return $this->steponeperson($form, $form_state); case 2: return $this->steptwocompany($form, $form_state); } }
when submit form doesn't load step 2 form after ajax call.
my question is: there code example or tutorial on topic? i'm doing wrong?
Comments
Post a Comment