jQuery-UI Dialog Buttons

How do we add buttons to the jQuery-UI Dialog?

I would expect the following, however it throws an error:




<?php

Dialog::begin([

    'clientOptions' => [

        'modal' => true,

		'autoOpen' => false,

		'title' => 'Dialog',

		'width' => '400px',

		'buttons' => [

			'Test' => 'js:function() { alert("test"); }',

			],

    ],

	'id' => 'testDialog',

]);


echo '<p>This is a dialog</p>';


Dialog::end();

?>



There may be no installation extension :

php composer.phar require --prefer-dist yiisoft/yii2-jui "*"

I have yii2-jui installed.

I can create and display dialogs just fine.

The question is: How do we add buttons to the jQuery-UI dialog?

Your grammar mistakes, I have encountered this situation, grammar is not correct

Please see the Dialog jQuery buttons parameter, you lost a bracket, YII framework to write JAVASCRIPT function support parameters are not perfect, like grammar:

‘buttons’=>[[‘text’= >’ OK’]]

But this is the problem - it is not at all documented: http://www.yiiframework.com/doc-2.0/yii-jui-dialog.html

If I use as you suggest, what is the parameter for the JS function call?




'buttons'=>[['text'= >' OK', <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' /> => 'js:function() {alert("test");}']]



The following works… kinda:




<?php

Dialog::begin([

    'clientOptions' => [

        'modal' => true,

                'autoOpen' => false,

                'title' => 'Dialog',

                'width' => '400px',

                'buttons' => [

                        ['text' => 'Test', 'onclick' => 'alert("test")'],

                ],

    ],

        'id' => 'testDialog',

]);


echo '<p>This is a dialog</p>';


Dialog::end();

?>



The only problem is that when the button is clicked it also throws the following error, from Firebug:




TypeError: click is undefined

	


click.apply( that.element[ 0 ], arguments );   	

	

jquery-ui.js (line 8550, col 4)



Does not anybody know the correct way to deploy buttons in a Yii2 dialog?

Updated code. This should be correct, but still fails with the same error:




<?php

Dialog::begin([

    'clientOptions' => [

        'modal' => true,

                'autoOpen' => false,

                'title' => 'Dialog',

                'width' => '400px',

                'buttons' => [

                        ['text' => 'Test', 'click' => 'js:function(){alert("test")}'],

                ],

    ],

        'id' => 'testDialog',

]);


echo '<p>This is a dialog</p>';


Dialog::end();

?>



The problem shows when viewing page source: the javascript has the function wrapped in double quotes:




     "buttons":[{"text":"Test","click":"js:function(){alert(\"test\")}"}]



This is the solution:




'buttons' => [

                ['text' => 'Test', 'click' => new JsExpression('js:function(){alert("test")}')],

             ],



JsExpression was going to tell you, that a subject can only reply 3, sorry