2015-05-31 47 views
2

我有我的觀點一個卡爾蒂克Yii2預輸入控件:卡爾蒂克Yii2的Widget事先鍵入的內容事件偵聽器不工作

echo \kartik\typeahead\Typeahead::widget([ 
    'name' => 'serial_product', 
    'options' => [ 
     'placeholder' => 'Product Name/SKU/Serial Number/Coupon Code', 
     'autofocus' => "autofocus", 
     'id' => 'serial_product' 
    ], 
    'scrollable' => TRUE, 
    'pluginOptions' => [ 
     'highlight' => TRUE, 
     'minLength' => 3 
    ], 
    'dataset' => [ 
     [ 
      'remote' => [ 
       'ttl' => 0, 
       'url' => Url::to(['invoice/ajaxgetinventoryitemsnew']) . '?search=%QUERY', 
       'ajax' => ['complete' => new \yii\web\JsExpression("function(response){jQuery('#serial_product').removeClass('loading');checkresult(response.responseText);return true}")] 
      ], 
      'limit' => 10 
     ] 
    ], 
    'pluginEvents' => [ 
     "typeahead:selected" => "function(obj, item) { checkresult2(item); return true; }", 
     "typeahead:render" => "function() { console.log('Whatever...'); }", 
    ], 
]); 

第一個「pluginEvents」(預輸入:選擇)是越來越觸發,因爲它應該。 第二個「typeahead:render」沒有被觸發,並且在控制檯上沒有錯誤。

爲什麼渲染事件沒有被觸發?

版本:typeahead.js 0.10.5 |卡爾蒂克Typeahead.php 1.0.0

回答

0

可能:使用卡爾蒂克\部件\事先鍵入的內容

$data = [ 
    'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 
    'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 
    'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana' 
]; 

// Usage with ActiveForm and model (with search term highlighting) 
echo \$form->field(\$model, 'state_3')->widget(Typeahead::classname(), [ 
    'options' => ['placeholder' => 'Filter as you type ...'], 
    'pluginOptions' => ['highlight'=>true], 
    'dataset' => [ 
     [ 
      'local' => $data, 
      'limit' => 10 
     ] 
    ] 
]); 
0

我測試你的代碼在我的項目。

use kartik\typeahead\Typeahead; 

<?= $form->field($model, 'country')->widget(Typeahead::classname(), [ 
    'pluginOptions' => ['highlight' => true], 
    'options' => [ 
     'placeholder' => 'Начните ввод страны' 
    ], 
    'dataset' => [ 
     [ 
      'local' => $countries, 
      'limit' => 10 
     ] 
    ], 
    'pluginEvents' => [ 
     "typeahead:selected" => "function(obj, item) { 
      console.log(item); return true; }", 
     "typeahead:render" => "function() { 
      console.log('Whatever...'); }", 
    ], 
    ]); 
?> 

它運作良好。任何時候我鍵入一個字符控制檯響應「無論...」。 「選定」事件也適用。

也許你的代碼不能像你期望的那樣工作,因爲checkresult2(item)函數。