3

--EDIT: This is now SOLVED.

I want one button to do multiple js commands, e.g.

$nextButton = $form->addButton('Next');

to do:

$button_repopulate_address->js(true)->show()
$street->js(true)->closest('fieldset')->show()

when:

$nextButton->isClicked()

The example code here suggests that you nest the commands in the 2nd paramater of the js call like this:

$g->addButton('Show all buttons')->js('click',$b1->js(null,$b2->js(null,$b3->js()->show())->show())->show());

I think this is very ugly and will create code that is very difficult to follow for more than 2 commands.

I looked in the source and found the _prepend command, which I've used to solved my problem by doing this:

if($nextButton->isClicked()){
      $form->js()->_prepend($street->js(true)->closest('fieldset')->show())
                 ->_prepend($button_repopulate_address->js(true)->show())
              ->execute();
}

EDIT: I just looked at the source of js() and it appears that you can pass an array to js which calls the _prepend method for each item in the array - nice!:

$form->js(null, array(
     $street->js(true)->closest('fieldset')->show(),
     $button_repopulate_address->js(true)->show()
));

--SOLVED (but perhaps the example I linked to could be updated with this much better functionality)

Richard EB
  • 967
  • 10
  • 24

1 Answers1

2

It is explained here:

http://agiletoolkit.org/learn/understand/chains/multi

The examples will be revised very shortly, we're working on a new example site.

romaninsh
  • 10,606
  • 4
  • 50
  • 70