Guest User

Untitled

a guest
Jan 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. $(document).ready(function()
  2. {
  3. var Count = 1;
  4.  
  5. $(".entry").children("select").select2({});
  6. $(".btn-add").click(function () {
  7. $(".entry")
  8. .children("select").each(function () {
  9. $(this)
  10. // call destroy to revert the changes made by Select2
  11. .select2("destroy")
  12. .removeAttr('data-live-search')
  13. .removeAttr('data-select2-id')
  14. .removeAttr('aria-hidden')
  15. .removeAttr('tabindex');
  16. });
  17. });
  18.  
  19.  
  20. $(document).on('click', '.btn-add', function(e)
  21. {
  22. e.preventDefault();
  23.  
  24. var controlForm = $('.controls fieldset:first-child'),
  25. currentEntry = $(this).parents('.entry:first'),
  26. newEntry = $(currentEntry.clone()).appendTo(controlForm);
  27.  
  28. newEntry.find('input').val('');
  29. controlForm.find('.entry:not(:last) .btn-add')
  30. .removeClass('btn-add').addClass('btn-remove')
  31. .html('<div id="rectangle"></div>');
  32.  
  33. $(".entry").children("select").each(function () {
  34. $(this).select2({});
  35. });
  36.  
  37. }).on('click', '.btn-remove', function(e)
  38. {
  39.  
  40. $(this).parents('.entry:first').remove();
  41. e.preventDefault();
  42.  
  43. $(".entry").children("select").each(function () {
  44. $(this).select2({});
  45. });
  46. return false;
  47. });
  48.  
  49. });
Add Comment
Please, Sign In to add comment