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

New Option if not exits #345

Open ered15 opened 7 years ago

ered15 commented 7 years ago

Hi, im using select2 plugin but im struggling with my code need it to add a new option if noResults, this is my code:

'pluginOptions' => [
    //'allowClear' => true,
    //'tags' => true,
    'minimumInputLength' => 3,
    'language' => [
        'errorLoading' => new JsExpression("function () { return 'Esperando resultados...'; }"),
        'inputTooShort' => new JsExpression("function () { return 'Ingrese 3 o más caracteres'; }"),
        'searching' => new JsExpression("function () { return 'Buscando...'; }"),
        'noResults' => new JsExpression("function () { return 'No se encontró ningún resultado'; }"),
    ],
    'createSearchChoice' => new JsExpression('function(term, data) {
        if ( $(data).filter( function() {
          return this.text.localeCompare(term)===0;
        }).length===0) {
          return {id:term, text:term};
        }
    }'),
    'ajax' => [
        'url' => $url_clientes,
        'dataType' => 'json',
        'tags' => true,
        'data' => new JsExpression('function(params) { return {q:params.term}; }'),
        'results' => new JsExpression('function(data,page) { return {results:data.results}; }')
    ],
    'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
    'templateResult' => new JsExpression('function(data) {  return data.text; }'),
    'templateSelection' => new JsExpression('function (data) { return data.text; }'),
],
'pluginEvents' => [
    "change" => 'function() {
    }'
],
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/48535826-new-option-if-not-exits?utm_campaign=plugin&utm_content=tracker%2F530581&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F530581&utm_medium=issues&utm_source=github).