   return null;
 
 formatAddNew = (data) ->
-  if ($('.select2-search__field')[0])
-    term = $('.select2-search__field')[0].value || ''
-  term = addnew + term
+  term = getSearchTerm() || ''
+  term = addnew + ' ' + term
   if (data.text.indexOf('Add new playlist') != -1 )
     return '<a>
               <i class="fa fa-plus" aria-hidden="true"></i> <b>'+term+'</b>
             </a>'
   return data.text
+
+showNewPlaylistModal = (playlistName) ->
+  console.log(playlistName)
 
 $("#post_playlist_id").select2({
   templateResult: formatAddNew

addnew = 'Add new playlist'

$('#post_playlist_id').append('<option>Add new playlist</option>')

matchWithNew = (params, data) ->
  params.term = params.term || ''

    (markup) -> return markup
  matcher: matchWithNew
  })
  .on('select2:selecting',
    (evt) ->
      choice = evt.params.args.data.text
      if (choice.indexOf(addnew) != -1)
        showNewPlaylistModal(getSearchTerm())
  )
