2amigos / yii2-multi-select-widget

Bootstrap MultiSelect and MultiSelect Listbox widgets for Yii2
https://2amigos.us
Other
45 stars 29 forks source link

Not possible to use widget options that need a callback as a parameter #13

Closed trombipeti closed 7 years ago

trombipeti commented 7 years ago

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.

tonydspaniard commented 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'; }") ]
trombipeti commented 7 years ago

Wow I didn't know that, thank you!