Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How override default "text" key to custom key? #4086

Closed
alexpts opened this issue Jan 15, 2016 · 2 comments
Closed

How override default "text" key to custom key? #4086

alexpts opened this issue Jan 15, 2016 · 2 comments

Comments

@alexpts
Copy link

alexpts commented Jan 15, 2016

{ id: 4, text: 'wontfix' }  ->  { id: 4, name: 'wontfix' }.
@kevin-brown
Copy link
Member

The docs are pretty terrible about recommending how to correct this issue.

The preferred way is to fix change the property names at the data source, so they match the id and text that Select2 is expecting. We understand that this isn't always possible, which is why we have a few hooks where you can do the mapping on the client side.

This is covered briefly in the 4.0.0 announcement:
https://select2.github.io/announcements-4.0.html#changed-id

I'm going to mark this as a documentation issue.

@kevin-brown kevin-brown added this to the 4.0.2 milestone Jan 15, 2016
@alexpts
Copy link
Author

alexpts commented Jan 15, 2016

May be create options for this keys?

$.fn.select2.defaults.set("pk-prop", "id");
$.fn.select2.defaults.set("text-prop", "text");

It allows you to work with own format objects wihtout transformation object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants