Skip to content

Commit

Permalink
Complete minimal example in README.md for nate-strauser#28
Browse files Browse the repository at this point in the history
  • Loading branch information
openp2pdesign committed Mar 30, 2018
1 parent b85cf14 commit 58bea9b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions README.md
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/).

0 comments on commit 58bea9b

Please sign in to comment.