Closed trombipeti closed 7 years ago
@trombipeti to use a callback function, is documented to use the JsExperession
class from Yii2. Try this:
'clientOptions' => [ 'buttonText' => ['callback' => new JsExpression("function(options, select) { return '42'; }") ]
Wow I didn't know that, thank you!
Use case: I would like to set e.g. the buttonText (or any other that needs a callback) option for the widget from PHP. It is not possible though.
Cause of the problem: "clientOptions" is Json::encode()-ed which essentially converts the function body to a string.
Proposed solution: Maybe something like: 'clientOptions' => [ 'buttonText' => ['callback' => "function(options, select) { return '42'; }" ] And then parse it accordingly.
If I missed something and this is already possible, please tell me how.