添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hi fellows, I’m trying to simply retrieve the text content on the change event of the select2 widget in yii-booster.

I get the val property value but not the text one. Do you have any idea ?

$this->widget('bootstrap.widgets.TbSelect2', array( 'asDropDownList' => true, 'name' => 'num_month', 'data' => array(1=>'1 month',2=>'2 months'), 'options' => array( 'width' => '45%', 'tokenSeparators' => array(',', ' '), 'events' =>array('change'=>'js:function(e) $("#amountm").text((e.val*9+9)+" € (" + e.text + ")");

Did anyone solve this? I have the same symptoms. The Yii Booster page does not have examples on how to correctly preload data and I suspect that the extension is unable to correctly retrieve the ‘text’ field just by looking at how the actual Select2 plugin works ( http://ivaynberg.github.io/select2/ ). It seems an associative array is passed in as the data parameter.

Additionally, the placeholder does not get populated correctly and just says, "undefined" in the dropbox.

Hi fellows, I’m trying to simply retrieve the text content on the change event of the select2 widget in yii-booster.

I’ve tried with choice, added and name. Nothing got me the text content of the selection.

I have some code similar to yours, did a console.log() on your ‘e’ variable under events->change, and I was able to see the selected text. Here’s my change function:

'change'=>'js: function(e) { console.log(e); alert(e.added.text);

Additionally, the placeholder does not get populated correctly and just says, "undefined" in the dropbox.

In order to get the placeholder to work, I had to add a blank item at the beginning of my data array. Hope this example helps:

$this->widget('bootstrap.widgets.TbSelect2', array( 'name'=>'my-dropdown', 'data'=>array( ''=>'', '1'=>'Item 1', '2'=>'Item 2', 'options'=>array( 'placeholder'=>'Select an item',