kartik-v / yii2-widgets

Collection of useful widgets for Yii Framework 2.0
http://demos.krajee.com/widgets
Other
558 stars 175 forks source link

Typing fast misses keystrokes - very wierd.... #307

Closed robov closed 8 years ago

robov commented 8 years ago

I have a select2 ajax implementation and it works marvelous Now I noticed something very wierd... when i type in (really fast) 'hypertension' The final call to the server is ?q=hypertensio (without the last n) The result is that the selectbox is empty...

When I backspace on the n it searches again "?q=hypertensio" and the proper values are diplayed in the box

When I then type the closing n again it searches and results correctly ( ?q=hypertension)

To make it even wierder... when i type in (really fast) 'hypertension ' (with an extra space) Then the search is again correct ?q=hypertension+

Any ideas ?

robov commented 8 years ago

`// The controller action that will render the list $url = \yii\helpers\Url::to(['citylist']);

// AJAX SEARCH echo $form->field($model, 'organsystem_id')->widget(Select2::classname(), [ //'id'=>'organsystematt-generic_audit_status_id', //.. set to complete ID , including prefix, so js canupdate thies //'id'=>'bcmpreference-resource_author_id', //.. set to complete ID , including prefix, so js canupdate thies 'initValueText' => 'oooo', //'attribute' => 'en_name',
'options' => [ 'placeholder' => Yii::t('app', 'Please select...') ], 'pluginOptions' => [ 'allowClear' => true, //'multiple' => true, 'minimumInputLength' => 3, 'language' => [ 'errorLoading' => 'waiting for resultsss', ],
'ajax' => [ 'url' => $url, 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }') ],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function(city) { return city.text; }'), 'templateSelection' => new JsExpression('function (city) { return city.id; }'),
],
]);`

kartik-v commented 8 years ago

This is more a plugin question (you may post to the author). But to answer, the behavior is typical of any ajax based search input box... you normally have a delay after which the ajax search is executed (for performance reasons)... and not instantly... so as a user you are expected to wait after some typing to get the search results.