{"id":16317855,"url":"https://github.com/buttflattery/yiiselect2","last_synced_at":"2025-10-25T17:30:51.059Z","repository":{"id":19495889,"uuid":"22742097","full_name":"buttflattery/yiiSelect2","owner":"buttflattery","description":"Select2 extension for Yii with event binding support and ajax text field option","archived":false,"fork":false,"pushed_at":"2018-09-11T12:23:58.000Z","size":95,"stargazers_count":12,"open_issues_count":0,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-31T09:41:55.714Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buttflattery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-08T01:33:37.000Z","updated_at":"2018-09-11T12:24:00.000Z","dependencies_parsed_at":"2022-09-14T13:41:31.543Z","dependency_job_id":null,"html_url":"https://github.com/buttflattery/yiiSelect2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buttflattery%2FyiiSelect2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buttflattery%2FyiiSelect2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buttflattery%2FyiiSelect2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buttflattery%2FyiiSelect2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buttflattery","download_url":"https://codeload.github.com/buttflattery/yiiSelect2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238183866,"owners_count":19430215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T22:09:25.735Z","updated_at":"2025-10-25T17:30:50.551Z","avatar_url":"https://github.com/buttflattery.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Select2 Extension for Yii\n\nExtension to use jQuery Plugin Select2 in Yii application.\n\ncourtesy Select2 script: https://github.com/ivaynberg/select2\n\n\n## Whats new \nEvent binding support for select2 yii extension no need to write any line of javascript configure the whole dropdow via select2 extension\n\n\n## Installation\nDownload or clone this repository and paste in `/protected/extensions/select2`\n\n\n## Usage\nDirect import into page \n```php\nYii::import('ext.select2.Select2');\n```\nOr in config to make it avaiable overall site\n```php\n    ...\n    'import' =\u003e array(\n        ...\n        'ext.select2.Select2',\n        ...\n    ),\n    ...\n```\n\n## Example:\n \u003cbr\u003e\nSimple call `Select2::dropDownList()`\nModel reference  `Select2::activeDropDownList()`\n\n## Advanced\n```php\n    ...\n    echo Select2::multiSelect(\"test\", '', array('Apple','Banana','Orange','Apricot','Black Current'), \n        array(\n            'required' =\u003e 'required',\n            'select2Options' =\u003e array(\n              'placeholder' =\u003e 'Please select a fruit',\n              'maximumSelectionSize' =\u003e 4,\n            ),\n        )\n    );\n    ...\n    echo Select2::activeMultiSelect($model, \"attr\", array('test1','test2'), array(\n        'placeholder' =\u003e 'This is a placeholder',\n    ));\n    ...\n```\nOr this\n\n```php\n    ...\n    $this-\u003ewidget('Select2', array(\n       'name' =\u003e 'exampleInput',\n       'value' =\u003e 1,\n       'data' =\u003e array(\n           1 =\u003e 'Apple',\n           2 =\u003e 'Banana',\n           3 =\u003e 'Orange',\n           4 =\u003e 'Apricot',\n        ),\n    ));\n    ...\n```\n## Initialize options with javascript function or expressions\nExample populating text field with ajax support\n```php\n    ...\necho Select2::dropDownList('location', '', array(),\n  array(\n      'empty'=\u003e'',\n      'id'=\u003e'location',\n      'style'=\u003e'width:100%',\n      'select2Options'=\u003earray(\n          'allowClear'=\u003etrue,\n          'placeholder'=\u003e'Type Location Here',\n           'minimumInputLength'=\u003e'3',\n          'ajax'=\u003earray(\n              'url'=\u003e'/homes/locationsajax/',\n              'type'=\u003e'GET',\n              'dataType'=\u003e'jsonp',\n              'data'=\u003enew CJavaScriptExpression('function (term, page) {return {loc_name: term, page:page}}'),\n              'results'=\u003enew CJavaScriptExpression('function (data, page) {return {results:  data.locations}}'),\n\n          ),\n          'initSelection'=\u003enew CJavaScriptExpression('function(element, callback) { '\n                    . 'var id=jQuery(element).val(); '\n                    . 'if (id!==\"\") {'\n                    . ' jQuery.ajax(\"/homes/locationsajax/loc_id/\"+id, { dataType: \"jsonp\" } ).done( function(data) {'\n                    . 'callback(data);'\n                    . '});'\n                    . '}}'),\n          'formatResult'=\u003e new CJavaScriptExpression('locationFormatResult'),\n          'formatSelection'=\u003enew CJavaScriptExpression('locationFormatSelection'),\n          'escapeMarkup'=\u003enew CJavaScriptExpression('function (m) {return m;}'),\n          )\n  )\n                            );\n    ...\n```\nfollowing  javascript is rendered by extension with the above piece of php code\n\n```javascript\n  ...\n  $('#location').select2(\n            {\n            'allowClear':true,\n            'placeholder':'Type Location Here',\n            'minimumInputLength':'3',\n            'ajax':{\n                'url':'/homes/locationsajax/',\n                'type':'GET',\n                'dataType':'jsonp',\n                'data':function (term, page) {return {loc_name: term, page:page}},\n                'results':function (data, page) {return {results:  data.locations}}},\n                'initSelection':function(element, callback) { \n                    var id=jQuery(element).val(); \n                    if (id!==\"\") { \n                      jQuery.ajax(\"/homes/locationsajax/loc_id/\"+id, { dataType: \"jsonp\" } )\n                      .done( function(data) {\n                              callback(data)\n                              }\n                        );\n                    }\n                  },\n                  'formatResult':locationFormatResult,\n                  'formatSelection':locationFormatSelection,\n                  'escapeMarkup':function (m) {return m;}\n            }\n  );\n  ...\n\n```\n\n## Binding Events Examples with dropdown list\nA dropdown example triggering the events \"select2-selecting\" and \"select2-removed\" \nwhich fire on selecting a choice and clearing a choice \n```php\n  ...\n    echo Select2::dropDownList('area_type', '', \n                array('sqft'=\u003e'Square Feet','marla'=\u003e'Marlas'),\n                array('empty'=\u003e'','id'=\u003e'area_type','style'=\u003e'width:100%',\n                    'select2Options'=\u003earray(\n                        'allowClear'=\u003etrue,\n                        'placeholder'=\u003e'Unit Type',\n                        'onTrigger'=\u003earray(\n                            'select2-selecting'=\u003enew CJavaScriptExpression('function(e) { console.log(e.object.id);}'),\n                            \"select2-removed\"=\u003enew CJavaScriptExpression('function(e) { console.log(e.choice.text);}'),\n                        )\n                        ),\n\n                    )\n                );\n  ...\n\n```\nThe following javascript is rendered when you run the above piece of code\n```javascript\n  ...\n   $('#area_type').select2(\n      {\n        'allowClear':true,\n        'placeholder':'Unit Type'\n      }\n    )\n    .on('select2-selecting',function(e) { console.log(e.object.id);})\n    .on('select2-removed',function(e) { console.log(e.choice.text);});\n  ...\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuttflattery%2Fyiiselect2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuttflattery%2Fyiiselect2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuttflattery%2Fyiiselect2/lists"}