You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
select2entity-bundle
2
2
====================
3
3
4
-
##Introduction##
4
+
##Introduction
5
5
6
6
This is a Symfony2 bundle which enables the popular [Select2](https://select2.github.io) component to be used as a drop-in replacement for a standard entity field on a Symfony form.
7
7
@@ -13,7 +13,7 @@ The project was inspired by [lifo/typeahead-bundle](https://github.com/lifo101/t
13
13
14
14
Thanks to @ismailbaskin we now have Select2 version 4 compatibility.
15
15
16
-
##Screenshots##
16
+
##Screenshots
17
17
18
18
This is a form with a single selection field list expanded.
19
19
@@ -23,7 +23,7 @@ This is a form with a multiple selection field list expanded.
Select2 must be installed and working first. I hope to setup a demo site but my setup is basically [BraincraftedBootstrapBundle](http://bootstrap.braincrafted.com) with Select2 installed for Bootstrap 3. Once the Braincrafted bundle is working, the only files I've needed to install are:
The following is for Symfony 3. The latest version works on both Symfony 2 and Symfony 2 but see https://github.com/tetranz/select2entity-bundle/tree/v2.1 for Symfony 2 configuration and use.
77
77
@@ -103,7 +103,7 @@ Put this at the top of the file with the form type class:
103
103
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;
104
104
```
105
105
106
-
##Options##
106
+
##Options
107
107
Defaults will be used for some if not set.
108
108
*`class` is your entity class. Required
109
109
*`primary_key` is the name of the property used to uniquely identify entities. Defaults to 'id'
@@ -146,7 +146,7 @@ tetranz_select2_entity:
146
146
scroll: true
147
147
```
148
148
149
-
##AJAX Response##
149
+
##AJAX Response
150
150
The controller should return a `JSON` array in the following format. The properties must be `id` and `text`.
151
151
152
152
```javascript
@@ -155,7 +155,7 @@ The controller should return a `JSON` array in the following format. The propert
155
155
{ id: 2, text: 'Displayed Text 2' }
156
156
]
157
157
```
158
-
##Infinite Scrolling##
158
+
##Infinite Scrolling
159
159
If your results are being paged via the Select2 "infinite scrolling" feature then you can either continue to return
160
160
the same array as shown above _(for Backwards Compatibility this bundle will automatically try to determine if more
161
161
results are needed)_, or you can return an object shown below to have finer control over the paged results.
@@ -174,7 +174,7 @@ The `more` field should be true if there are more results to be loaded.
174
174
Your controller action that fetches the results will receive a parameter `page` indicating what page of results should
175
175
be loaded. If you set scroll to true then you must handle the page parameter in the query. Weird things will happen if you don't.
176
176
177
-
##Custom option text##
177
+
##Custom option text
178
178
If you need more flexibility in what you display as the text for each option, such as displaying the values of several fields from your entity or showing an image inside, you may define your own custom transformer.
179
179
Your transformer must implement DataTransformerInterface. The easiest way is probably to extend EntityToPropertyTransformer or EntitiesToPropertyTransformer and redefine the transform() method. This way you can return as `text` anything you want, not just one entity property.
180
180
@@ -204,7 +204,7 @@ Your custom transformer and respectively your Ajax controller should return an a
204
204
```
205
205
If you are using the allow_add option and your entity requires other fields besides the text_property field to be valid, you will either need to extend the EntitiesToPropertyTransformer to add the missing field, create a doctrine prePersist listener, or add the missing data in the form view after submit before saving.
206
206
207
-
###Add New Tags###
207
+
###Add New Tags
208
208
209
209
If you want to be able to create new entities through Select2 tags, you can enable it using the `allow_add` set of options.
210
210
@@ -242,7 +242,7 @@ $builder
242
242
```
243
243
244
244
245
-
###Templating###
245
+
###Templating
246
246
247
247
If you need [Templating](https://select2.github.io/examples.html#templating) in Select2, you could consider the following example that shows the country flag next to each option.
248
248
@@ -301,7 +301,7 @@ You also will need to override the following block in your template:
301
301
```
302
302
This block adds all additional data needed to the JavaScript function `select2entityAjax`, like data attribute. In this case we are passing `data-img`.
303
303
304
-
##Embed Collection Forms##
304
+
##Embed Collection Forms
305
305
If you use [Embedded Collection Forms](http://symfony.com/doc/current/cookbook/form/form_collections.html) and [data-prototype](http://symfony.com/doc/current/cookbook/form/form_collections.html#allowing-new-tags-with-the-prototype) to add new elements in your form, you will need the following JavaScript that will listen for adding an element `.select2entity`:
0 commit comments