title: Select2: Update option after selecting new tag
body: <p>I implemented a tagging system where you can choose from existing tags or add new tags. After a new tag has been selected it will persisted using an AJAX call.</p>
  
  <p>For achieving this I use the callback <code>createTag</code> and the event <code>select2:select</code>. Because I like to create the tag only when it is selected I do an AJAX call for this if the event <code>select2:select</code> gets triggered.</p>
  
  <p>The problem is that I need to update the already created option of select2 with the ID I get from persisting my new tag to the database. What's the cleanest solution for this?</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>$('select.tags').select2({
       tags: true,
       ajax: {
           url: '{{ path('tag_auto_complete') }}',
           processResults: function (data) {
               return {
                   results: data.items,
                   pagination: {
                       more: false
                   }
               };
           }
       },
       createTag: function (tag) {
           return {
               id: tag.term, // &lt;-- this one should get exchanged after persisting the new tag
               text: tag.term,
               tag: true
           };
       }
   }).on('select2:select', function (evt) {
       if(evt.params.data.tag == false) {
           return;
       }
  
       $.post('{{ path('tag_crrate_auto_complete') }}', { name: evt.params.data.text }, function( data ) {
          // ----&gt; Here I need to update the option created in "createTag" with the ID
          option_to_update.value = data.id;
  
       }, "json");
   });
  </code></pre>