kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

Bad Request (#400): Invalid data received for parameter "search". #175

Closed RGTimothy closed 5 years ago

RGTimothy commented 8 years ago

I was using Yii 2.0.3 with select2 widget. Its been working until I update my composer (also update all dependencies automatically) today.

Then now I always get this error whenever I type some string : "Bad Request (#400): Invalid data received for parameter "search"."

This is my code below

$initScript = <<< SCRIPT
function (element, callback) {
    var id=\$(element).val();
    if (id !== "") {
        \$.ajax("{$url}?id=" + id, {
        dataType: "json"
        }).done(function(data) {
            callback(data.results);
        });
    }
}
SCRIPT;
    //echo $datetime_now;
    echo $form->field($model, 'customer_id')->widget(Select2::classname('tes'), [
        'options' => ['placeholder' => 'Search for a Customer ...'],
        'pluginOptions' => [
            'allowClear' => true,
            'minimumInputLength' => 1,
            'ajax' => [
                'url' => $url,
                'dataType' => 'json',
                'data' => new JsExpression('function(term,page) { return {search:term}; }'),
                'results' => new JsExpression('function(data,page) { 
                    if(data.results != 0) { 
                        $("#custid").val(data.results[0]["id"]);
                    }
                    else {}
                    return {results:data.results}; 
                }'),
            ],
            'initSelection' => new JsExpression($initScript),
            // 'formatNoMatches'=>'No matches found. Click here to add new Customer',
            'formatNoMatches'=>'No matches found. You can contact Customer Service to add a new customer data.',
        ],
        'pluginEvents' => [
            "change" => 'function(data) { 
                var data_id = data.added["id"];
                $("#custid").val(data_id);
            }',
        ],
    ]);
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.