Reputation: 3502
I'm opening a form for editing some record. I'm using an "infinite scroll select2".
I want the input to show the option already saved to that field (I'm editing a record...)
How can I do that? This way is not working:
$('#e7').select2('data', { id: 8, text: 'foo' });
I've created a jsfiddle to show that: http://jsfiddle.net/lucianocosta/Dyh8W/1/
Upvotes: 2
Views: 4530
Reputation: 3502
ivaynberg answered me: https://github.com/ivaynberg/select2/issues/688#issuecomment-11971899
you have to pass in an object that is in the same format as what your renderers expect. in this case the renderer you specified expects the title attribute, not text. see here: http://jsfiddle.net/Dyh8W/2/
So the solution here is:
$('#e7').select2('data', { id: 8, title: 'foo' });
Upvotes: 1