Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function buildForm(array $form, FormStateInterface $form_state) {
- ...
- if($form_state->getValue('g_actualPartIndex') == NULL){
- $form_state->setValue('g_actualPartIndex', 0);
- }
- $form = $this->setHeader($form, $form_state);
- $form['Next'] = array(
- '#type' => 'submit',
- '#value' => "Go to next step",
- '#ajax' => [
- 'wrapper' => 'projekt-form-wrapper',
- 'callback' => [$this, 'form_ajax_submit'],
- 'method' => 'replace',
- 'effect' => 'fade'
- ]
- );
- $form['#prefix'] = '<div id="projekt-form-wrapper">';
- $form['#suffix'] = '</div>';
- return $form;
- }
- public function form_ajax_submit($form, $form_state) {
- $form_state->setValue('g_actualPartIndex',
- (int)($form_state->getValue('g_actualPartIndex')) + 1);
- $form = $this->setHeader($form, $form_state);
- $response = new AjaxResponse();
- $response->addCommand(new HtmlCommand(
- '#projekt-form-wrapper',
- $form
- ));
- return $response;
- }
- private function setHeader(array $form, FormStateInterface $form_state){
- $actualPartIndex = $form_state->getValue('g_actualPartIndex');
- $form['header'] = array(
- '#type' => 'markup',
- '#markup' => t('<div id="generatorHeader">
- <span class="part '.($actualPartIndex == 0 ? 'active' : '').'">Part 1</span>
- <span class="part '.($actualPartIndex == 1 ? 'active' : '').'">Part 2</span>
- <span class="part '.($actualPartIndex == 2 ? 'active' : '').'">Part 3</span>
- <span class="part '.($actualPartIndex == 3 ? 'active' : '').'">Part 4</span>
- <span class="part '.($actualPartIndex == 4 ? 'active' : '').'">Part 5</span>
- <span class="part '.($actualPartIndex == 5 ? 'active' : '').'">Part 6</span>
- </div>'),
- );
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement