I installed the JUI Extension for Yii 2 from https://github.com/yiisoft/yii2-jui.
With the following code, the creation of widget is OK:
echo Spinner::widget(array(
'name' => 'year',
'value' => $year,
'clientOptions' => array(
'min' => '2000',
'step' => 1,
),
'clientEvents' => ['spin' => "onSpin"],
));
The HTML code is:
jQuery('#w0').spinner({"min":"2000","step":1});
jQuery('#w0').on('spinnerspin', onSpin);
But the event’s name ‘spinnerspin’ isn’t correct (see: http://api.jqueryui.com/spinner/#event-spin).
This event’s name is generated by the function registerClientEvents in the class ‘yii\jui\Widget’.
protected function registerClientEvents($name)
{
if (!empty($this->clientEvents)) {
$id = $this->options['id'];
$js = [];
foreach ($this->clientEvents as $event => $handler) {
if (isset($this->clientEventsMap[$event])) {
$eventName = $this->clientEventsMap[$event];
} else {
$eventName = $name.$event;
}
$js[] = "jQuery('#$id').on('$eventName', $handler);";
}
$this->getView()->registerJs(implode("\n", $js));
}
}
The variable $clientEventsMap is protected, so it’s not possible to set the widget with ‘clientEventsMap’ => [‘spin’ => ‘spin’].
I don’t understand this design. Why is event’s name prefixed by $name? Why is it not possible to set clientEventsMap?