Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ meteor add natestrauser:select2

## How to use

Add a specific class in your template for the select element you want to apply Select2 to:
Add a specific class in your template for the select element you want to apply Select2 to (and read the value of _data-id_):

```html
<select class="select2-dropdown" name="state">
<option value="value1">value1</option>
<option value="value2">value2</option>
<select class="select2-dropdown" name="state" id="select2-example">
<option value="value1" data-id="id1">value1</option>
<option value="value2" data-id="id2">value2</option>
</select>
```

Expand All @@ -34,4 +34,22 @@ Template.MyTemplate.onRendered(function() {
});
```

Add a function for the selection event:

```javascript
'change select': function(event, template) {
var id = $('#select2-example option:selected').data('id');
}
```

Or for any other events:

```javascript
'click #save-button': function(event, template) {
var id = $('#select2-example option:selected').data('id');
}
```



See also the [Select2 documentation](https://select2.org/).
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Package.on_use(function(api) {
api.use("jquery", "client");

api.add_files([
"lib/select2/dist/js/select2.js"
"lib/select2/dist/js/select2.full.min.js"
], "client", { bare: true });

api.add_files([
Expand Down