我的上述問題的另一種解決方法是如下:
,但我不知道這是正確的/標準方式或不..但對我來說:)做工精細
這裏是我的看法:typeheadbasic擴展
$clientData = $my_dynamic_data_arr; // this arr var i used in jquery script for chekcing if name is exists or not
echo TypeaheadBasic::widget([
'model' => $model,
'attribute' => 'client',
'data' => $clientData,
'options' => ['placeholder' => 'Filter as you type ...', 'id' => 'client_profile'],
'pluginOptions' => ['highlight' => true],
]);
這裏是我的jQuery腳本來處理上述問題
var client_arr = $.makeArray(<?php echo json_encode(array_values($clientData)); ?>); // $clientData is php array variable from above
$("#clientProfileForm").submit(function(event) {
var client_name = $("#client_profile").val();
if ($.inArray(client_name, client_arr) === -1) {
$("#clientProfileError").html("<spna style='color:red'>Client not exists</span>");
return false;
}
if ($('#client_profile').val() === '') {
event.preventDefault();
$("#clientProfileError").html("<spna style='color:red'>Client name is required</span>");
}
});
爭奪w「選擇Repository」部分.http://demos.krajee.com/widget-details/typeahead。 – yafater